-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmidtermQ6.java
More file actions
27 lines (27 loc) · 822 Bytes
/
Copy pathmidtermQ6.java
File metadata and controls
27 lines (27 loc) · 822 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import java.util.Scanner;
public class midtermQ6 {
static boolean isAutomorphic(int a)
{
int sq = a * a;
while (a> 0) {
if (a % 10 != sq % 10)
return false;
a /= 10;
sq /= 10;
}
return true;
}
public static void main(String[] args)
{Scanner keyboard = new Scanner(System.in);
char answer = 'n';
System.out.print("Enter a number: ");
int a = keyboard.nextInt();
System.out.println(isAutomorphic(a) ? "Automorphic" : "Not Automorphic");
System.out.println("DO YOU WANT TO CONTINUE ? Y OR N");
answer = keyboard.next().charAt(0);
if(answer == 'n' || answer == 'N'){
System.exit(0);
keyboard.close();
}
}
}