Professional Documents
Culture Documents
1
SL. NO. QUESTION PAGE NO
Write a program for calculating difference between the areas of two circles
1 with radius 20 cm & 30 cm. Display both the radius, areas along with their 4
difference as the final output. (use PI = 3.14)
Write a java program for displaying all the even numbers from 1 – 100 with a
2 tab space, as shown below,2 4 6 8 10…… 6
Write a java program for displaying all the odd numbers from 1 – 100 with a
3 tab space, as shown below,1 3 5 7 9…… 8
Write a java program for calculating the product of even & odd numbers from 1
4 – 10. Display the numbers along with their sums individually 10
Write a java program which takes month number as user input and displays the
7 number of days in every month based on the user’s input. E.g., When user 17
enters ‘1’ then display : “January – This month has 31 days”
9 Write a java program for displaying all Armstrong number between 0-1000 21
29
WAP TO FIND THE FREQUENCY OF EACH DIGIT OF A NUMBER
13
2
SL. NO. QUESTION PAGE NO
W.A.P to take input any integer no. Find the Minimum Prime Factor
18 present in the no 39
Write a program to take input any number. Find min & max digit
23 49
3
/*Q1: Write a program for calculating difference between the areas of two circles with
radius 20 cm & 30 cm. Display both the radius, areas along with their difference as the
final output. (use PI = 3.14)*/
class Circle
{
public static void main(String args[])
{
int r1=20;
int r2=30;
double A1=3.14*r1*r1;
double A2=3.14*r2*r2;
double diff=A2-A1;
System.out.println("Radius of 1st circle="+r1+","+"Radius of 2nd circle="+r2);
4
5
/*Q2:Write a java program for displaying all the even numbers from 1 – 100 with a tab
space, as shown below,2 4 6 8 10……*/
class EvenNo
{
public static void main(String args[])
{
int r1=1;
int r2=100;
while(r1<=r2)
{
if(r1%2==0)
System.out.print(r1+" ");
r1++;
}
}
6
7
/*Q3:Write a java program for displaying all the odd numbers from 1 – 100 with a tab
space, as shown below,1 3 5 7 9……*/
class OddNo
{
public static void main(String args[])
{
int r1=1;
int r2=100;
while(r1<=r2)
{
if(r1%2!=0)
System.out.print(r1+" ");
r1++;
}
}
8
9
/*Q4:Write a java program for calculating the product of even & odd numbers from 1 –
10. Display the numbers along with their sums individually*/
class Even_Odd
{
public static void main(String args[])
{
int r1=1;
int r2=10;
int pro=1,sum=0,pro2=1,sum2=0;
System.out.print("Even:");
while(r1<=r2)
{
if(r1%2==0)
{
pro*=r1;
sum+=r1;
System.out.print(r1+" ");
}
r1++;
}
System.out.print("Odd:");
r1=1;
while(r1<=r2)
{
if(r1%2!=0)
{
pro2*=r1;
sum2+=r1;
System.out.print(r1+" ");
}
r1++;
}
System.out.println("Sum of odd no.="+sum2+","+"Product of odd no.="+pro2+","+"Sum of even
no.="+sum+","+"Product of even no.="+pro); } }
10
11
/*Q5:Import the Math class. Create a user-defined class named as “Math_Functions”;
take two variables x & y, having values 10 & 20.
Write the program to calculate –
a. maximum number
b. minimum number
c. square root of y
d. cube root of x
e. find the value of yx & xy
f. log(x) and log(y) using Math Functions; and display all the values in the main()
function.*/
import java.util.Scanner;
class Math_Function
{
int x=10,y=20;
void max()
{
int max=Math.max(x,y);
System.out.println("Maximum="+max);
}
void min()
{
double min=Math.min(x,y);
System.out.println("Minimum="+min);
}
void sqrt()
{
double sqrt=Math.sqrt(y);
System.out.println("Square root="+sqrt);
}
void cbrt()
{
double cbrt=Math.cbrt(x);
12
System.out.println("Cube root"+cbrt);
}
void product()
{
int pro=x*y;
System.out.println("xy="+pro+","+"yx="+pro);
}
void logarithm()
{
double l1=Math.log(x);
double l2=Math.log(y);
System.out.println("log(x):"+l1+","+"log(y):"+l2);
}
public static void main(String args[])
{
Math_Function obj=new Math_Function();
obj.max();
obj.min();
obj.sqrt();
obj.cbrt();
obj.product();
obj.logarithm();
}}
13
14
/*Q6:Create a class ‘CompareNo’ having two functions ‘max()’ & ‘min()’ with three
parameters (a, b, c) for finding the maximum & minimum number from the three
numbers. Write the main() function which creates an object of class to invoke both the
methods.*/
import java.util.Scanner;
class CompareNo
{ int a,b,c;
void input()
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter 3 Numbers");
a=sc.nextInt();
b=sc.nextInt();
c=sc.nextInt();
}
void max()
{
int max=Math.max(a,Math.max(b,c));
System.out.println("Maximun="+max);
}
void min()
{
int min=Math.min(a,Math.min(b,c));
System.out.println("Minimum="+min);
}
public static void main(String args[])
{
CompareNo obj=new CompareNo();
obj.input();
obj.max();
obj.min();
}}
15
16
/*Q7: Write a java program which takes month number as user input and displays the
number of days in every month based on the user’s input. E.g., When user enters ‘1’ then
display : “January – This month has 31 days”.*/
import java.util.Scanner;
class Month{
else if(mn==8)
System.out.println("August-This month has 31 Days");
else if(mn==9)
System.out.println("September-This month has 30 Days");
else if(mn==10)
System.out.println("October-This month has 31 Days");
else if(mn==11)
System.out.println("November-This month has 30 Days");
else if(mn==12)
System.out.println("December-This month has 31 Days"); }}
17
18
/*Q8: Write a java program to display Fibonacci series up to 15 terms. e.g. 0, 1, 1, 2, 3, 5,
8, 13….*/
class Fibonacci
{
public static void main(String args[])
{
int n=15,a=0,b=1;
if(n==1)
System.out.print(a);
else if (n>=2)
{
System.out.print(a+","+b+",");
for(int i=1;i<=n-2;i++)
{
int c=a+b;
a=b;
b=c;
System.out.print(c+",");
}
}}}
19
20
//Q9: Write a java program for displaying all Armstrong number between 0-1000
class ArmstrongNumber{
public static void main(String args[]){
int lc=0,n=lc;
int sum=0;
int ctr = 0;
while(ctr<=1000){
while(lc>0)
{
int d=lc%10;
sum=sum+d*d*d;
lc/=10;
}
if(sum==n)
System.out.print(sum+",");
ctr++;
n++;
lc+=n;
sum=0;
}
}
21
22
/*Q10: Write a program to check whether the number is Neon number or not.
Example : 9 = 9*9 = 81 = 8+1 = 9 */
import java.util.Scanner;
class NeonNo
{
public static void main(String args[])
{
int a=0;
while(s>0)
{
a+=s%10;
s/=10;
}
if(a==n)
System.out.println("It is a neon number");
else
23
24
/*Q11: WAP TO TAKE INPUT two numbers. find LCM & HCF*/
import java.util.Scanner;
class HCF_LCM
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
System.out.println("enter 2 numbers");
int a=sc.nextInt();
int b=sc.nextInt();
int s=Math.min(a,b);
while(s>=1)
{
if(a%s==0&&b%s==0)
break;
s--;
}
int l=(a*b)/s;
System.out.println("HCF="+s+","+"LCM="+l);
}}
25
26
/*Q12: WAP TO MERGE TWO INTEGER NOS .*/
import java.util.Scanner;
class Join
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter 2 no.");
int a=sc.nextInt();
int b=sc.nextInt();
int n2=b;
int e=1;
while(n2>0)
{
e*=10;
n2/=10;
}
int j=a*e+b;
System.out.println("After joining:"+j);
}}
27
28
/*Q13: WAP TO FIND THE FREQUENCY OF EACH DIGIT OF A NUMBER*/
import java.util.Scanner;
class Frequency
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
System.out.println("enter a numbers");
int n=sc.nextInt();
System.out.println("Digit \t Frequency");
for(int i=0;i<=9;i++)
{
int c=0;
int N=n;
while(N >0)
{
int rem=N%10;
if(rem==i)
c++;
N/=10;
}
if(c!=0)
System.out.println(i+"\t"+c);
}}}
29
30
/*Q14: WAP to find sum s=1+(x/1)+(x/2)+(x/3)+ ………..n terms*/
import java.util.Scanner;
class Series_1
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
System.out.println("enter a numbers");
int x=sc.nextInt();
System.out.println("enter the terms");
int t=sc.nextInt();
int ctr=1;
double s=0;
int n=2;
while(ctr<t)
{
s+=x/n;
ctr++;
n++;
}
System.out.println((1+s));
}}
31
32
/*Q15: WAP to find sum s=5+55+555+5555+….n terms*/
import java.util.Scanner;
class Series_2
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter The Number Of Terms...");
int n=sc.nextInt();
int a=5,sum=0;
while(n>0)
{
sum=sum+a;
a=a*10+5;
n--;
}
System.out.println("The sum="+sum);
}
33
34
/* Q16: WAP to find sum: s=1+12+123+1234+ ............................................ n terms*/
import java.util.Scanner;
class Series_3
{
public static void main(String arg[])
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter The Number Of Terms");
int n=sc.nextInt();
int a=1,b=2,sum=0;
while(n>0)
{
sum+=a;
a=a*10+b;
b++;
n--;
}
System.out.println("Sum="+sum);
}
}
35
36
/*Q17: WAP to find sum s=1+10+100+1000+ ....... n terms*/
import java.util.Scanner;
class Series_4
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter The Number Of Terms...");
int n=sc.nextInt();
int a=1,sum=0;
while(n>0)
{
sum=sum+a;
a=a*10;
n--;
}
System.out.println("The sum="+sum);
}
37
38
/*Q18 W.A.P to take input any integer no. Find the Minimum Prime Factor present in the
no*/
import java.util.Scanner;
class Prime_Factor
{
public static void main (String args[])
{
while(ctr<=n)
{
if(n%ctr==0)
{
System.out.println("Minimum prime factor="+ctr);
break;
}
ctr++;
} }}
39
40
/*Q19: W.A.P to Check the number is a NELSON number or not, it is a no which has 3
same digits.*/
import java.util.Scanner;
class Nelson_No
{
public static void main(String args[])
{
while(n>0)
{
d=n%10;
if(d==ld)
ctr++;
c++;
n/=10;
}
if(ctr==c)
41
42
/*Q20: Write a program to take input any number. check it is EVIL or not . It is a number
which has even no of 1 or even no of 0 or odd no of 1 or odd no of 0*/
import java.util.Scanner;
class Evil_No
{
public static void main(String args[])
{
c++;
}
if(c%2==0)
System.out.println("It is a evil number");
else
System.out.println("It is not a evil number");
}}
43
44
/*Q21: W.A.P to check the number is a PALPRIME number or not (prime + palindrome) */
import java.util.Scanner;
class PalPrime
{
public static void main(String args[])
{
Scanner sc= new Scanner(System.in);
int n,p,rev,s=0,i,c=0;
System.out.println("Enter No.");
n= sc.nextInt();
p=n;
for(i=1;i<=p;i++)
{
if(p%i==0)
{
c++;
}
}
while(n>0)
{
rev=n%10;
s=s*10+rev;
n=n/10;
}
if(p==s&&c==2)
45
46
/*Q22: W.A.P to take input any number , Print ALL EVEN DIGITS*/
import java.util.Scanner;
class Even_Digit
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
System.out.println("enter a numbers");
int n=sc.nextInt();
int d=0;
while(n>0)
{
d=n%10;
if(d%2==0)
System.out.print(d+" ");
n/=10;
}}}
47
48
/*Q23: Write a program to take input any number . Find min & max digit*/
import java.util.Scanner;
class MinMaxDigit
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
System.out.println("enter a number");
int n=sc.nextInt();
int largest = 0;
int smallest = 9;
while(n != 0)
{
int r = n % 10;
largest = Math.max(r, largest);
49
50
/*Q24: Write a program to check whether the number is Neon number or not.
Example : 9 = 9 * 9 = 81 = 8 + 1 = 9 */
import java.util.Scanner;
class Neon_No2
{
a+=s%10;
s/=10;
}
if(a==n)
51
52
/*Q25: Write a program to check a number is an Armstrong number or not*/
import java.util.Scanner;
class Armstrong_2
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
System.out.println("enter a numbers");
int n=sc.nextInt();
int a=n,d=0,c=0;
while(a>0)
{
d=a%10;
c=c+(d*d*d);
a/=10;
}
System.out.println(c==n?"It is a armstrong no.":"It is not a armstrong no.");
}}
53
54
/*Q26: Write a program to check a number is a Prime number or not*/
import java.util.Scanner;
class PrimeNo
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
System.out.println("enter a numbers");
int n=sc.nextInt();
int c=0,i=1;
while(i<=n)
{
if(n%i==0)
c++;
i++;
}
if(c==2)
System.out.println(n+" is a prime number");
else
System.out.println(n+" is not a prime number");
}}
55
56
/*Q27: Write a program to check a number is a Perfect number or not*/
import java.util.Scanner;
class PerfectNo
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
System.out.println("enter a number");
int n=sc.nextInt();
int ctr=1,sum=0;
while(ctr<n)
{
if(n%ctr==0)
sum=sum+ctr;
ctr++;
}
if(sum==n)
System.out.println("It is a perfect number");
else
System.out.println("It is not a perfect number");
}
}
57
58
/*Q28: Write a program to check a number is a Composite number or not*/
import java.util.Scanner;
class CompositeNo
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
System.out.println("enter a numbers");
int a=sc.nextInt();
int n=0;
for(int i=1;i<=a;i++)
{
if(a%i==0)
n++;
}
if(n>2)
59
60
/*Q29: Write a program to check a pair of numbers are twine prime numbers or not*/
import java.util.Scanner;
class TwinPrime
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
int c=0,i=1;
while(i<=n)
{
if(n%i==0)
c++;
i++;
}
int c2=0,i2=1;
while(i<=n2)
{
if(n2%i2==0)
c2++;
i2++;
}
int diff=n-n2;
if(diff==2)
System.out.println("It is a Twin prime number");
else
System.out.println("It is not a Twin prime number");
}}
61
62
/*Q30: Write a program to check a number is a Niven number or not*/
import java.util.Scanner;
class NivenNo
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
System.out.println("enter a numbers");
int N=sc.nextInt();
int n=N;
int sum=0;
int d=0;
while(n>0)
{
d=n%10;
sum+=d;
n/=10;
}
if(N%sum==0)
System.out.println("It is niven number");
else
63
64