write a program in java to accept a number from the user and check weather it is buzz number or an automorphic number .
1. An automorphic number is a number whose Square's last digit(s) is equal to that number. Eg- the square of 25 is 625 and the last two digits of 625 are 25. Hence, 25 is an automorphic number.
2. A buzz number is a number which ends with 7 or is divisible by 7.
Answers
public class Automorphic_Buzz
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
System.out.print("Enter a number: ");
int n = sc.nextInt();
System.out.println();
boolean a = isAutomorphic(n);
boolean b = isBuzz(n);
if((a==true)&&(b==true))
{
System.out.println(n+" is both an Automorphic and Buzz Number");
}
else if(a==true)
{
System.out.println(n+" an Automorphic Number");
}
else if(b==true)
{
System.out.println(n+" is a Buzz Number");
}
else
{
System.out.println(n+" is neither an Automorphic nor a Buzz Number");
}
}
static boolean isAutomorphic(int n)
{
int d=0,m; //d will contain the sum of digits of n
double p;
m=n;
while (m!=0)
{
m=m/10;
d++;
}
m=n*n;
p = m%(Math.pow(10,d));
if (n==p)
return true;
else
return false;
}
static boolean isBuzz(int n)
{
if((n%10 == 7)||(n%7 ==0))
{
return true;
}
else
{
return false;
}
}
}
CODE :
import java.util.*;
class brainly
{
public void main()
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter a number");
int n=sc.nextInt();
int r =checkauto(n);
int s =checkbuzz(n);
if(r==1)
{
System.out.println("Automorphic number");
}
else
{
System.out.println("Not a automorphic number");
}
if(s==1)
{
System.out.println("Buzz number");
}
else
{
System.out.println("Not a buzz number");
}
}
int checkauto(int n)
{
int sq=n*n;
int c=0,s=0,cpy=n*n;
while(sq>0)
{
c=sq%10;
s++;
sq=sq/10;
}
double a=cpy % Math.pow(10,s-1);
if(a==n)
{
return 1;
}
else
{
return 0;
}
}
int checkbuzz(int n)
{
if((n%10 == 7)||(n%7 ==0))
{
return 1;
}
else
{
return 0;
}
}
}