-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLooping3.java
More file actions
27 lines (23 loc) · 765 Bytes
/
Looping3.java
File metadata and controls
27 lines (23 loc) · 765 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
public class Looping3 {
public static void main(String args[]) {
//is the sum of n with n reverse a palindrome? if yes, n++ if no, (till hundred times) n = n + n reverse.
long O = Long.parseLong(args[0]);
long M = 1;
for (long i = 1; i <= O; i++) {
//turn n backwards and assign it to R
String s = "";
Long N = M;
while (M > 0) {
s += M % 10;
M = M / 10;
}
long R = Long.parseLong(s);
//Überlauftest
if (N+R > Long.MAX_VALUE) {
System.out.println("Überlauf");
} else {
System.out.println(N+R);//korrekt, ohne Ueberlauf
}
}
}
}