0% found this document useful (0 votes)
55 views

Number Logic Java

The document contains Java code snippets that define classes to check if a given number meets certain mathematical properties such as being automorphic, ambica, Armstrong, happy, Kaprekar, magic, neon, perfect, special, triangular, etc. Each class contains a main method that takes user input, performs calculations to test the property, and prints whether the number meets the property or not.

Uploaded by

Krishna Gupta
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)
55 views

Number Logic Java

The document contains Java code snippets that define classes to check if a given number meets certain mathematical properties such as being automorphic, ambica, Armstrong, happy, Kaprekar, magic, neon, perfect, special, triangular, etc. Each class contains a main method that takes user input, performs calculations to test the property, and prints whether the number meets the property or not.

Uploaded by

Krishna Gupta
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/ 7

import java.util.

Scanner;
class Automorphic
{
void main()
{
Scanner x = new Scanner (System.in);
System.out.println("Enter a No.");
int n = x.nextInt();
int N = n;
int c= 0 ;
while(N>0)
{
c++;
N/=10;
}
N = n*n;
int d = (int)Math.pow(10,c);
int r = N%d;
if(r==n)
{
System.out.println("Entered No. is Automorphic No.");
}
else
{
System.out.println("Entered No. is not Automorphic No.");
}
}
}

import java.util.Scanner;
class ambica
{
void main()
{
System.out.println("Enter two no.s");
Scanner x = new Scanner(System.in);
System.out.println("Enter two no.s");
long n = x.nextLong();
int s=0,s1=0;
for (long i =1;i<=n/2;i++)
{
if(n%i==0)
{
s+=i;
}
}
long k = x.nextLong();
for (long i =1;i<=k/2;i++)
{
if(k%i==0)
{
s1+=i;
}
}
if(s==k&&s1==n)
System.out.println("the entered number is a ambica number");
else
System.out.println("the entered number is not a ambica number");
}
}

import java.util.Scanner;
class ARMSTRONG
{
void main()
{
int s=0,c=0,k=0;
Scanner x = new Scanner(System.in);
System.out.println("ENTER THE NO.");
int n =x.nextInt();
int a = n;
while(a!=0)
{
c=a%10;
k=c*c*c;
s+=k;
a/=10;
}
if(s==n)
{
System.out.println("THE ENTERED NO. "+n+" IS ARMSTRONG");
}
else
{
System.out.println("THE ENTERED NO. "+n+" IS NOT
ARMSTRONG");
}
}
}

public class HAPPYNO


{
void digitFrequency()
{
System.out.println("Happy Numbers are");
int c = 0;
int s = 0;
for(int i = 0; i<=1000;i++)
{
int a = i ;
while(a>9)
{
while(a!=0)
{
c=a%10;
s+=(c*c);
a/=10;
}
a=s;
s=0;
//System.out.println(a);
}
if(a==1)
{
System.out.println(i);
}
}
}
}

import java.util.Scanner;
class isc2017
{
void main()
{
Scanner x = new Scanner (System.in);
System.out.println("Enter a No. of Boxes To be packed ");
int n = x.nextInt();
int N = n;
int a[] = {48,24,12,6};
int b[] = {0,0,0,0};
for(int i = 0 ;i<4;i++)
{
b[i] = N/a[i];
N%=a[i];
System.out.println("Cartoon of capacity "+a[i]+" boxes
required
:: "+b[i]);
}
System.out.println("Remaining No. of Boxes unpacked "+N);
}
}

import java.util.Scanner;
class kaprekar_No
{
void main()
{
Scanner x = new Scanner (System.in);
System.out.println("Enter a No.");
int n = x.nextInt();
int N = n;
int c= 0 ;
while(N>0)
{
c++;
N/=10;
}
N = n*n;
int d = (int)Math.pow(10,c);
int r = N%d;
int l = N/d;
if((l+r)==n)
{
System.out.println("Entered No. is a Kaprekar No.");
}
else
{
System.out.println("Not kap");
}
}
}

import java.util.*;
class MAGIC
{
void generate()
{
Scanner x = new Scanner(System.in);
System.out.println("Enter a number");
int n = x.nextInt();
if(n%9==1)
{
System.out.println("A MAGIC NUMBER");
}
else
{
System.out.println("NOT A MAGIC NUMBER");
}
}
}

import java.util.Scanner;
class NEON
{
void main()
{
int s=0,c=0,k=0;
Scanner x = new Scanner(System.in);
System.out.println("ENTER THE NO.");
int n =x.nextInt();
int a = n*n;
while(a!=0)
{
c=a%10;
s+=c;
a/=10;
}
if(s==n)
{
System.out.println("THE ENTERED NO. "+n+" IS A NEON NO. ");
}
else
{
System.out.println("THE ENTERED NO. "+n+" IS NOT NEON NO.
");
}
}
}

import java.util.*;
class PERFECT
{
void check()
{
long n;
long s= 0;
Scanner x = new Scanner(System.in);
System.out.println("Enter a number");
n = x.nextLong();
for (long i =1;i<=n/2;i++)
{
if(n%i==0)
{
s+=i;
}
}
if(s==n)
System.out.println("the entered number is a Perfect number");
else
System.out.println("the entered number is not a Perfect number");
}
}
import java.util.Scanner;
class special_no
{
void main()
{
Scanner x = new Scanner (System.in);
System.out.println("Enter a No.");
int n = x.nextInt();
int N = n;
int c = 0 ;
int s = 0;
int r = 1 ;
while(N>0)
{
c=N%10;
for(int i = 1; i<=c;i++)
r*=i;
s+=r;
N/=10;
r=1;
}
if(s==n)
{
System.out.println("Entered No. is Special No.");
}
else
{
System.out.println("Not a Special no.");
}
}
}

class TriangularNo
{
void main(int n)
{
int c = 0 ;
int f = 0;
for(int i = 1;i<=n;i++)
{
c+=i;
if(c==n)
{
f=-1;
}
}
if(f==-1)
{
System.out.println("Entered No. Is Triangular Number");
}
else
{
System.out.println("Entered No. Is Not a Triangular Number");
}
}
}

You might also like