-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathKaprekar1.java
More file actions
32 lines (24 loc) · 857 Bytes
/
Kaprekar1.java
File metadata and controls
32 lines (24 loc) · 857 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
28
29
30
31
32
import java.util.Scanner;
public class Kaprekar1 {
// main method begins execution of this class
public static void main(String args[]) {
int square, temp, counter = 0, rem, quo;
Scanner sc = new Scanner(System.in);
System.out.print("Enter a number greater than 1: ");
// Waiting for the user input
int n = sc.nextInt();
temp = n;
square = n * n;
while (n != 0) {
counter++;
n = n / 10;
}
rem = square % ((int) Math.pow(10, counter));
quo = square / ((int) Math.pow(10, counter));
if ((rem + quo) == temp) {
System.out.println(temp + " is a kaprekar number ");
} else {
System.out.println(temp + " is not a kaprekar number ");
}
} // end method main
} // end cla