WAP A Menu driven program to enter a number and check whether it is a unique number or not or automorphic number or not
(in java)
QGP:
Does automorphic mean that the number is contained in the last digits of its square?
Answers
Answered by
34
import java.util.*;
public class Brainly
{
void automorph(int n)
{
int d=0,m,f;
double p;
m=n;
while (m!=0)
{
m=m/10;
d++;
}
m=n*n;
p = m%(Math.pow(10,d));
System.out.println(n+"*"+n+"="+m);
if (n==p)
System.out.println(n+" is an Automorphic number.");
else
System.out.println(n+" is not an Automorphic number.");
}
void unique(int n)
{
int l,i,j,f=0;
String s;
s = Integer.toString(n);
l = s.length();
for(i=0;i<l;i++)
{
for(j=0;j<i;j++)
{
if (s.charAt(i)==s.charAt(j))
{
f=1;
break;
}
}
if (f==1)
break;
}
if(f==0)
System.out.println(n+" is a Unique number.");
else
System.out.println(n+" is not a Unique number.");
}
public static void main(String[] args)
{
Scanner in = new Scanner(System.in);
int ch,n;
System.out.println("1) To check for Unique Number");
System.out.println("2) To check for Automorphic Number");
System.out.print("Enter your choice: ");
ch = in.nextInt();
Brainly ob = new Brainly();
switch(ch)
{
case 1:
System.out.print("Enter number: ");
n = in.nextInt();
ob.unique(n);
break;
case 2:
System.out.print("Enter number: ");
n = in.nextInt();
ob.automorph(n);
break;
default:
System.out.println("Invalid Choice.");
break;
}
}
}
public class Brainly
{
void automorph(int n)
{
int d=0,m,f;
double p;
m=n;
while (m!=0)
{
m=m/10;
d++;
}
m=n*n;
p = m%(Math.pow(10,d));
System.out.println(n+"*"+n+"="+m);
if (n==p)
System.out.println(n+" is an Automorphic number.");
else
System.out.println(n+" is not an Automorphic number.");
}
void unique(int n)
{
int l,i,j,f=0;
String s;
s = Integer.toString(n);
l = s.length();
for(i=0;i<l;i++)
{
for(j=0;j<i;j++)
{
if (s.charAt(i)==s.charAt(j))
{
f=1;
break;
}
}
if (f==1)
break;
}
if(f==0)
System.out.println(n+" is a Unique number.");
else
System.out.println(n+" is not a Unique number.");
}
public static void main(String[] args)
{
Scanner in = new Scanner(System.in);
int ch,n;
System.out.println("1) To check for Unique Number");
System.out.println("2) To check for Automorphic Number");
System.out.print("Enter your choice: ");
ch = in.nextInt();
Brainly ob = new Brainly();
switch(ch)
{
case 1:
System.out.print("Enter number: ");
n = in.nextInt();
ob.unique(n);
break;
case 2:
System.out.print("Enter number: ");
n = in.nextInt();
ob.automorph(n);
break;
default:
System.out.println("Invalid Choice.");
break;
}
}
}
Answered by
4
Answefuck
Explanation:
Similar questions