0% found this document useful (0 votes)
16 views18 pages

Comp Project - 231108 - 155322

Program java project

Uploaded by

sankhamatter
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views18 pages

Comp Project - 231108 - 155322

Program java project

Uploaded by

sankhamatter
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 18

7.

import java.util.*;
public class p7 {
public static void main(String[]
args) {
Scanner sc=new Scanner
(System.in );
System.out.println("Enter a
number");
int n=sc.nextInt();
int t=n;
int c=0;
int r,s=0;
while (t>0)
{
t=t/10;
c++;
}
while(t>0)
{
r=t%10;
s+=(Math.pow(r,c));
t=t/10;
}
if(s==n)
{
System.out.println(n+" is
Armstrong number");
}
else
{
System.out.println(n+" is not
Armstrong number");
}
}
}
Output:
Enter a number
153
153 is Armstrong number

8.
import java.util.*;
public class p8
{
public static void main(String[]
args)
{
Scanner sc= new Scanner
(System.in );
System.out.println("Enter n ");
int n =sc.nextInt();
double i;
double s=0.0;
for(i=2;i<=n;i=i*2)
{
s=s+ 1/i;
}
System.out.println("Sum of
series: "+s);
}
}
Output:
Enter n
25
Sum of series: 0.9375
9 (a).
import java.util. *;
public class p9a{
public static void main(String[]
args) {
Scanner sc =new Scanner
(System.in );
System.out.println("Enter number
of rows");
int n=sc.nextInt();
int i,j,k;
for(i=1;i<=n;i++)
{
for(j=n;j>i;j--)
{
System.out.print(' ');
}
for(k=1;k<=i;k++)
{
System.out.print("*");
}
System.out.println();
}
}
}
Output:
Enter number of rows
6
*
**
***
****
*****
******

9 (b).
import java.util. *;
public class p9b {
public static void main(String[]
args) {
Scanner sc = new Scanner
(System.in );
System.out.println("Enter number
of rows");
int n=sc.nextInt();
int i,j;
for (i=5;i>=1;i--)
{
for(j=1;j<=i;j++)
{
System.out.print(j);
}
System.out.println();
}
}
}
Output:
Enter number of rows
5
12345
1234
123
12
1
10.
public class Main {
public static void main(String[]
args) {
String s="ICSE";
int l=s.length();
int i,j;
for (i=0;i<l;i++)
{
for(j=0;j<=i;j++)
{
System.out.print(s.charAt(j));
}
System.out.println();
}
}
}
Output:
I
IC
ICS
ICSE
11.

21.
import java.util.*;
public class p21 {
public static void main(String[]
args) {
Scanner sc =new Scanner
(System.in );
String s;
char ch, n;
System.out.println("Enter a
sentence");
s=sc.nextLine();
System.out.println("Enter a
character");
n=sc.next().charAt(0);
int l=s.length();
int i, c=0;
for(i=0;i<l; i++)
{
if(s.charAt(i)==n)
{
c++;
}
}
if(c>0)
{
System.out.println(n+" repeated
"+c+" times");
}
else
{
System.out.println("Entered
characternot found");
}
}
}
Output:
Enter a sentence
help Me jrlo
Enter a character
l
l repeated 2 times

22.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy