-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathq4.java
More file actions
28 lines (27 loc) · 726 Bytes
/
q4.java
File metadata and controls
28 lines (27 loc) · 726 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
//Find the largest pallindrome made from the product of two 3-digit numbers.
package code;
public class q4 {
public static void main(String[] args) {
long m = 0;
for(int i = 999; i >=0; i--) {
for(int j = 999; j >= 0; j--) {
long p = i * j;
if(p == reverse(p) && p > m) {
m = p;
}
}
}
System.out.println(m);
}
public static long reverse(long n) {
long reverse = 0;
while (n != 0) {
long l= n % 10;
reverse = reverse * 10 + l;
n /= 10;
}
return reverse;
}
}
//output:
//906609