NUMBERS
1.
Write
a program to find the number is perfect number or not.
import
java.util.*;
class
perfect
{
void main()
{
int n, i, s=0;
Scanner ob=new Scanner(System.in);
System.out.println("Enter the
number");
n=ob.nextInt();
for(i=1;i<n;i++)
{
if(n%i==0)
s=s+i;
}
if(s==n)
System.out.print("The number is
perfect number");
else
System.out.print("The number is
not a perfect number");
}
}
2.
Write
a program to find the number is amicable number or not.
import
java.util.*;
class
amicable
{
void main()
{
int a, b, i, j, sa=0, sb=0;
Scanner ob=new Scanner(System.in);
System.out.println("Enter first
number");
a=ob.nextInt();
System.out.println("Enter second
number");
b=ob.nextInt();
for(i=1;i<a;i++)
{
if(a%i==0)
sa=sa+i;
}
for(j=1;j<b;j++)
{
if(b%j==0)
sb=sb+j;
}
if(sa==b && sb==a)
System.out.print("The number is
amicable number");
else
System.out.print("The number is
not a amicable number");
}
}
3.
Write
a program to find the number is spy number or not.
import
java.util.*;
class
spy
{
void main()
{
int a, d=0, s=0, p=1;
Scanner ob=new Scanner(System.in);
System.out.print("Enter the
number"); //123
a=ob.nextInt();
while(a>0)
{
d=a%10;
s=s+d;
p=p*d;
a=a/10;
}
if(s==p)
System.out.print("The number
is spy");
else
System.out.print("The number
is not a spy");
}
}
4.
Write
a program to find the number is neon number or not.
import
java.util.*;
class
neon
{
void main()
{
int a, sq=0, d=0, s=0;
Scanner ob=new Scanner(System.in);
System.out.print("Enter the
number");
a=ob.nextInt();
sq=a*a;
while(sq>0)
{
d=sq%10;
s=s+d;
sq=sq/10;
}
if(s==a)
System.out.print("The number is
neon number");
else
System.out.print("The number is
not a neon number");
}
}
5.
Write
a program to find the number is automophic number or not.
import
java.util.*;
public
class automophic
{
void main()
{
int n, d=0, c=1, r=0, a, sq=0;
Scanner ob=new Scanner(System.in);
System.out.print("Enter the
number");
n=ob.nextInt();
a=n;
sq=n*n;
while(n>0)
{
d=n%10;
c=c*10;
n=n/10;
}
r=sq%c;
if(r==a)
System.out.print("The number is
automophic number");
else
System.out.print("The number is
not a automophic number");
}
}
6.
Write
a program to find the number is Armstrong number or not.
import
java.util.*;
class
armstrong
{
void main()
{
int a, d=0, s=0, n;
Scanner ob=new Scanner(System.in);
System.out.print("Enter the
number");
a=ob.nextInt();
n=a;
while(n>0)
{
d=n%10;
s=s+(d*d*d);
n=n/10;
}
if(s==a)
System.out.print("The number is
armstrong number");
else
System.out.print("The number is
not a armstrong number");
}
}
7.
Write
a program to find all two digit spy number.
import
java.util.*;
class
spy
{
void main()
{
int i, a, d=0, s=0, p=1;
for(i=100;i<=999;i++)
{
a=i;
while(a>0)
{
d=a%10;
s=s+d;
p=p*d;
a=a/10;
}
if(s==p)
System.out.print(" "+i);
s=0;
p=1;
}
}
}
8.
Write
a program to find the number is tech number or not.
import
java.util.*;
class
tech
{
public static void main()
{
int a, d=0, c=1,r=0,q=0,sq=0,n;
double u=0.0;
Scanner ob=new Scanner (System.in);
System.out.print("Enter the number
");
a=ob.nextInt();
u=Math.sqrt(a);
sq=(int)u;
n=sq;
while(sq>0)
{
d=sq%10;
c=c*10;
sq=sq/10;
}
r=a%c;
q=a/c;
if((r+q)==n)
System.out.print("The number is
tech");
else
System.out.print("The number is
not a tech");
}
}
9.
Write
a program to find the number is palindrome number or not.
import
java.util.*;
class
palandromic
{
void main()
{
int a, d=0, r=0, n;
Scanner ob=new Scanner(System.in);
System.out.print("Enter the
number");
a=ob.nextInt();
n=a;
while(n>0)
{
d=n%10;
r=(r*10)+d;
n=n/10;
}
if(r==a)
System.out.print("The number is
palandromic number");
else
System.out.print("The number is
not a palandromic number");
}
}
10. Write a program to find the number
is special number or not.
import
java.util.*;
class
special_number
{
void main()
{
int a, n, d=0, f=1, i, s=0;
Scanner ob=new Scanner(System.in);
System.out.println("Enter the
number");
a=ob.nextInt();
n=a;
while(n>0)
{
d=n%10;
for(i=d;i>=1;i--)
{
f=f*i;
}
s=s+f;
n=n/10;
f=1;
}
if(s==a)
System.out.println("The number is
special number");
else
System.out.println("The number is
not a special number");
}
}
11. Write a program to convert the
number into binary number.
import
java.util.*;
class
binary
{
void main()
{
Scanner ob=new Scanner(System.in);
System.out.print("Enter the
number");
int n=ob.nextInt();
int d=0, r=0;
while(n>0)
{
d=n%10;
r=r*10+d;
n=n/10;
}
System.out.print("The reverse
number is "+r);
}
}
No comments:
Post a Comment