0% found this document useful (0 votes)
5 views16 pages

Number Classification Program in Java

Uploaded by

araj94536
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)
5 views16 pages

Number Classification Program in Java

Uploaded by

araj94536
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

/*

* Program to do tasks given in question in menu

* driven form.

*/

import [Link].*;

public class Program_7

// Function to check whether the number is Tech Number or not

public void Tech(int n)

int m = n;

int c =0;

while(n>0)

c++;

n/=10;

if(c%2==0)

int a = n/(int)[Link](10,c/2);

int b = n%(int)[Link](10,c/2);

if((a+b)*(a+b)==n)

[Link]("It is a Tech Number.");

else

[Link]("It is not a Tech Number.");

else
{

[Link]("It is not a Tech Number.");

// Function to check whether the number is Dudeney Number or not

public void Dudeney( int n )

int s = 0;

int cb = (int)[Link](n);

while(n>0)

s+= n%10;

n/= 10;

if(s==cb)

[Link]("It is a Dudeney Number.");

else

[Link]("Not a Dudeney Number.");

// Function to check the Number is Evon Number or not

public void EVON( int m )

int c = 0;

int c1 = 0;

while(m>0)

c1++;
if((m%10)%2==0)

c++;

m/= 10;

if(c1==c)

[Link]("It is a EVON Number.");

else

[Link]("Not a EVON Number.");

// Function to check whether the number is neon number or not

public void Neon(int n)

int sq = n*n;

int s = 0;

while(sq>0)

s+= sq%10;

sq/= 10;

if(s==n)

[Link]("It is a Neon Number.");

else

{
[Link]("Not a Neon Number.");

// Function to check whether the number is Niven Number or not

public void Niven(int n)

int s = 0;

int m = n;

while(m>0)

s+= m%10;

m/= 10;

if(n%s==0)

[Link]("It is a NIVEN Number.");

else

[Link]("Not a NIVEN Number.");

// Function to check whether the number is Pronic Number or not

public void Pronic(int n)

for(int x = 1; x<=n; x++)

if(x*(x+1)==n)

[Link]("It is a Pronic Number.");

break;
}

if(x*(x+1)>n)

[Link]("Not a Pronic Number.");

break;

// Function to check whether the number is Spy Number or not

public void Spy(int n)

int s = 0;

int p = 1;

while(n>0)

int d = n%10;

s+= d;

p*= d;

n/= 10;

if(s==p)

[Link]("It is a Spy Number.");

else

[Link]("Not a Spy Number.");

// Function to check whether the number is Abundant Number or not

public void Abundant(int n)


{

int s = 0;

for(int x = 1; x<n; x++)

if(n%x==0)

s+=x;

if(n<s)

[Link]("It is a Abundant Number.");

else

[Link]("Not a Abundant Number.");

// Function to check whether the number is Deficient Number or not

public void Deficient(int n)

int s = 0;

for(int x = 1; x<n; x++)

if(n%x==0)

s+=x;

if(n>s)

{
[Link]("It is a Deficient Number.");

else

[Link]("It is not a Deficient Number.");

// Function to check whether the number is Binary Number or not

public boolean IsBinary(int n)

boolean b = false;

while(n>0)

if((n%10)>1)

b = true;

n /= 10;

return b;

// Function to convert Binary to Decimal Number

public void Binary2Decimal(int n)

if(IsBinary(n))

[Link]("Enter a proper binary number.");

else

int s = 0;
int p = 0;

while(n>0)

int d = n%10;

s += d*(int)[Link](2,p);

p++;

n /= 10;

[Link]("Decimal Evaluation = "+s);

// Function to check whether the number is Magic Number or not 1st Part

public int IsMagic(int n)

int s = 0;

while(n>0)

s += (int)[Link]((n%10),2);

n /= 10;

if(s<10)

return s;

else

return(IsMagic(s));

// Function to check whether the number is Magic Number or not 2nd Part

public void Magic(int n)


{

if(IsMagic(n)==1)

[Link]("It is a Magic Number.");

else

[Link]("It is not a Magic Number.");

// Function to check whether the number is Lead Number or not

public void Lead(int n)

int se = 0;

int so = 0;

while(n>0)

int d = n%10;

if(d%2==0)

se += d;

else

so += d;

n /= 10;

if(se==so)

[Link]("It is a Lead Number.");


}

else

[Link]("It is not a Lead Number.");

// Function to find Factorial of a number

public int Factorial(int n)

int f = 1;

for(int x = 1; x<=n; x++)

f *= x;

return f;

// Function to check whether the number is Peterson Number or not

public void Peterson(int n)

int m = n;

int s = 0;

while(m>0)

s += Factorial(m%10);

m /= 10;

if(n==s)

[Link]("It is a Peterson Number.");

else
{

[Link]("It is not a Peterson Number.");

// Function to check whether the number is Sunny Number or not

public void Sunny(int n)

int m = n;

m++;

if([Link](m%1)==0.0)

[Link](n+" is a Sunny Number.");

else

[Link](n+" is not a Sunny number.");

// Function to convert Decimal to Binary Number

public void Decimal2Binary(int n)

int j = 0;

while(n>0)

int r = n%2;

j = j*10+r;

n /= 10;

[Link]("Binary Evaluation = "+j);

// Function to check whether the number is Twin Prime Number or not


public void TwinPrime(int n, int m)

if([Link](n-m) == 2)

int c1 = 0;

int c2 = 0;

int o = [Link](n,m);

for(int x = 1; x <= o; x++)

if(n%x == 0)

c1++;

if(m%x == 0)

c2++;

if(c1==2 && c2==2)

[Link](n+" and "+m+" are Twin Prime");

else

[Link](n+" and "+m+" are not Twin Prime");

else

[Link](n+" and "+m+" are not Twin Prime");


}

// Function to check whether the number is Twisted Prime Number or not

public void Twisted(int n)

int c1 = 0;

int m = n;

int rev = 0;

while(m>0)

rev = (rev*10)+(m%10);

m /= 10;

int c2 = 0;

int max = [Link](n,rev);

for(int x = 1; x<=max; x++)

if(n%x==0)

c1++;

if(rev%x == 0)

c2++;

if(c1==2 && c2 == 2)

[Link](n+" is a Twisted Prime.");

else
{

[Link](n+" is not a Twisted Prime.");

// Main function of the program

public static void main()

Scanner sc = new Scanner([Link]);

[Link]("Menu");

[Link]("[Link] Number \[Link] Number \[Link] Number");

[Link]("[Link] Number \[Link] Number \[Link] Number");

[Link]("[Link] Number \[Link] Number \[Link] Number");

[Link]("[Link] convert Binary to Decimal \[Link] Number");

[Link]("[Link] Number \[Link] Number \[Link] Number");

[Link]("[Link] convert Decimal to Binary \[Link] Number");

[Link]("[Link] Prime");

[Link]("Enter your choice :");

int ch = [Link]();

Program_7 p7 = new Program_7();

if(ch!=16)

[Link]("Enter a Number :");

else

[Link]("Enter 1st Number :");

int n = [Link]();

switch(ch)

case 1: [Link](n);
break;

case 2: [Link](n);

break;

case 3: [Link](n);

break;

case 4: [Link](n);

break;

case 5: [Link](n);

break;

case 6: [Link](n);

break;

case 7: [Link](n);

break;

case 8: [Link](n);

break;

case 9: [Link](n);

break;

case 10: p7.Binary2Decimal(n);

break;

case 11: [Link](n);

break;

case 12: [Link](n);

break;

case 13: [Link](n);

break;

case 14: [Link](n);

break;

case 15: p7.Decimal2Binary(n);

break;

case 16: [Link]("Enter 2nd Number :");

int m = [Link]();
[Link](n,m);

break;

case 17: [Link](n);

break;

default : [Link]("Invalid Choice");

You might also like