Lot of numbers are there to write a java program. Due to this coding only, These numbers have been recognized by the programming community and to the rest of the society.They makes the java language easy to the beginners and acts as a basement for tougher tasks to perform.
These numbers are Armstrong number,Adam number,Neon number,Krishna murthy number and many more
1) Program to check whether a number is Adam number or not....
12*12=144
21*21=441
Hence 12 is an adam number...
import java.util.*;
class adam
{
public static void main(String args[])
{
int n,rev=0,b,c,n1=0,rsq=0;
Scanner sc=new Scanner(System.in);
System.out.println("Enter the number");
n=sc.nextInt();
int n2=n;
int sq;
sq=n*n;
while(n>0)
{
b=n%10;
rev=rev*10+b;
n=n/10;
}
rsq=rev*rev;
while(rsq>0)
{
c=rsq%10;
n1=n1*10+c;
rsq=rsq/10;
}
if(n1==sq)
System.out.println("The number"+n2+"is adam number");
else
System.out.println("The number "+n2+"is not adam number");
}
}
2) Program to check whether a number is neon number or not......
9*9=81
8+1=9
Hence 9 is a neon number
import java.util.*;
class neon
{
public static void main(String args[])
{
int n,sq,b=0,c=0;
Scanner sc=new Scanner(System.in);
System.out.println("Enter the number");
n=sc.nextInt();
sq=n*n;
while(sq>0)
{
b=sq%10;
c=c+b;
sq=sq/10;
}
if(n==c)
{
System.out.println("The number is "+n+" is a Neon number");
}
else
{
System.out.println("The number is "+n+" is not a Neon number");
}
}
}
3)Program to find whether a number is Armstrong number or not....
153=1^3+5^3+3^3
Hence 153 is an armstrong number
import java.util.*;
class armstrongnumber
{
public static void main(String args[])
{
int num,a,b=0;
Scanner sc=new Scanner(System.in);
System.out.println("Enter the number");
num=sc.nextInt();
int n=num;
while(num>0)
{
a=num%10;
b=b+(int)Math.pow(a,3);
num=num/10;
}
if(n==b)
System.out.println(n+"Is a Armstrong number");
else
System.out.println(n+"Is not an Armstrong number");
}
}
4)Program to find whether the number is a Krishnamoorthy number or not
145=1!+4!+5!
Here 145 is a krishnamoorthy number
import java.util.*;
class krishna
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
int n,a,rem,k=0,p,i;
System.out.println(Ënter the number");
n=sc.nextInt();
a=n;
while(n!=0)
{
p=1;
rem=n%10;
n=n/10;
for(i=1;i<=rem;i++)
{
p=p*i;
}
k=k+p;
}
if(k==a)
System.out.println("KRISHNAMOORTHY NUMBER");
else
System.out.println("NOT A KRISHNAMOORTHY NUMBER");
}
}
These numbers are Armstrong number,Adam number,Neon number,Krishna murthy number and many more
1) Program to check whether a number is Adam number or not....
12*12=144
21*21=441
Hence 12 is an adam number...
import java.util.*;
class adam
{
public static void main(String args[])
{
int n,rev=0,b,c,n1=0,rsq=0;
Scanner sc=new Scanner(System.in);
System.out.println("Enter the number");
n=sc.nextInt();
int n2=n;
int sq;
sq=n*n;
while(n>0)
{
b=n%10;
rev=rev*10+b;
n=n/10;
}
rsq=rev*rev;
while(rsq>0)
{
c=rsq%10;
n1=n1*10+c;
rsq=rsq/10;
}
if(n1==sq)
System.out.println("The number"+n2+"is adam number");
else
System.out.println("The number "+n2+"is not adam number");
}
}
2) Program to check whether a number is neon number or not......
9*9=81
8+1=9
Hence 9 is a neon number
import java.util.*;
class neon
{
public static void main(String args[])
{
int n,sq,b=0,c=0;
Scanner sc=new Scanner(System.in);
System.out.println("Enter the number");
n=sc.nextInt();
sq=n*n;
while(sq>0)
{
b=sq%10;
c=c+b;
sq=sq/10;
}
if(n==c)
{
System.out.println("The number is "+n+" is a Neon number");
}
else
{
System.out.println("The number is "+n+" is not a Neon number");
}
}
}
3)Program to find whether a number is Armstrong number or not....
153=1^3+5^3+3^3
Hence 153 is an armstrong number
import java.util.*;
class armstrongnumber
{
public static void main(String args[])
{
int num,a,b=0;
Scanner sc=new Scanner(System.in);
System.out.println("Enter the number");
num=sc.nextInt();
int n=num;
while(num>0)
{
a=num%10;
b=b+(int)Math.pow(a,3);
num=num/10;
}
if(n==b)
System.out.println(n+"Is a Armstrong number");
else
System.out.println(n+"Is not an Armstrong number");
}
}
4)Program to find whether the number is a Krishnamoorthy number or not
145=1!+4!+5!
Here 145 is a krishnamoorthy number
import java.util.*;
class krishna
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
int n,a,rem,k=0,p,i;
System.out.println(Ënter the number");
n=sc.nextInt();
a=n;
while(n!=0)
{
p=1;
rem=n%10;
n=n/10;
for(i=1;i<=rem;i++)
{
p=p*i;
}
k=k+p;
}
if(k==a)
System.out.println("KRISHNAMOORTHY NUMBER");
else
System.out.println("NOT A KRISHNAMOORTHY NUMBER");
}
}