0% found this document useful (0 votes)
8 views5 pages

All Number Programs

The Java program allows users to check various properties of numbers, including prime, automorphic, Niven, disarium, perfect, buzz, deficient, abundant, palindrome, and neon numbers. Users select a choice from a menu and input a number, after which the program performs the corresponding check and outputs the result. The program utilizes conditional statements and loops to determine the properties of the input number.

Uploaded by

fekilit562
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)
8 views5 pages

All Number Programs

The Java program allows users to check various properties of numbers, including prime, automorphic, Niven, disarium, perfect, buzz, deficient, abundant, palindrome, and neon numbers. Users select a choice from a menu and input a number, after which the program performs the corresponding check and outputs the result. The program utilizes conditional statements and loops to determine the properties of the input number.

Uploaded by

fekilit562
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/ 5

import java.util.

*;
public class all_number_programs
{
void main()
{
Scanner sc=new Scanner(System.in);
int choice,n;
System.out.println("1.To check prime number");
System.out.println("2.To check automorphic number");
System.out.println("3.To check niven number");
System.out.println("4.To check disarium number");
System.out.println("5..To check perfect number");
System.out.println("6.To check buzz number");
System.out.println("7.To check deficient number");
System.out.println("8.To check abundant number");
System.out.println("9.To check palindrome number");
System.out.println("10.To check neon number");
choice=sc.nextInt();

System.out.println("----------------------");
System.out.println("Enter your number");
n=sc.nextInt();

switch(choice)
{
case 1:
int c=0,i;
for(i=1; i<=n; i++)
{
if(n%i==0)
{
c++;
}
}
if(c==2)
System.out.println("It is a prime number");
else
System.out.println("Not a prime number");
break;
case 2:
int numCopy = n;
int sq = n * n;
int d = 0;

/*
* Count the number of
* digits in num
*/
while(n > 0)
{
d++;
n /= 10;
}

/*
* Extract the last d digits
* from square of num
*/
int ld = (int)(sq % Math.pow(10, d));

if (ld == numCopy)
System.out.println(numCopy + " is automorphic");
else
System.out.println(numCopy + " is not automorphic");
break;

case 3:
int s=0,nc=n;
while(n>0)
{
d=n%10;
s=s+d;
n/=10;

}
if(nc%s==0)
System.out.println("Niven number");
else
System.out.println("Not a niven number");
break;
case 4:
int r,po=0,j=0,ppp=n;
s=0;
for(r=n; r>0; r/=10)
{
j++;
}
while(ppp>0)
{
d=ppp%10;
po=s+(int)Math.pow(d,j);/*sum of the respective digits
squares*/
ppp/=10;
j--;
}
if(po==n)
System.out.print("it is a disarium number"+n);
break;
case 5:
s=0;
int np=n;
for(r=1;r<n;r++)
{
if(n%r==0){
s=s+r;
}

}
if(s==np)
System.out.println("It is a perfect number");
else
System.out.println("not a perfect number");
break;
case 6:

if(n%7==0||n%10==7)
System.out.println("It is a buzz number");
else
System.out.println("Not a buzz number");
break;
case 7:
np=n;

s=0;
for(r=1;r<n;r++)
{
if(n%r==0)
{
s=s+r;
}
}
if(s<np)
System.out.println("It is a deficient number");
else
System.out.println("It is not a deficient number");
break;

case 8:
np=n;

s=0;
for(r=1;r<n;r++)
{
if(n%r==0)
{
s=s+r;
}
}
if(s>np)
System.out.println("It is a abundant number");
else
System.out.println("It is not a abundant number");
break;
case 9:
np=n;
r=0;
d=0;
while(np>0)
{
d=np%10;
r=r*10+d;
np/=10;
}
if(r==n)
System.out.println("It is a palindrome number");
else
System.out.println("It is not a palindrome number");
break;

case 10:
np=n;
s=0;
d=0;
sq=np*np;
while(sq!=0)
{
d=sq%10;

s=s+d;
sq/=10;
}
if(s==n)
System.out.println("It is a neon number");
else

System.out.println("It is not a neon number");


break;

default:System.out.println("Invalid input,Enter the correct choice");


break;
}}}

You might also like