-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathP4sec.java
More file actions
51 lines (45 loc) · 1.38 KB
/
P4sec.java
File metadata and controls
51 lines (45 loc) · 1.38 KB
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
class P4sec
{
public static void main(String[] args)
{
//Stopwatch timer = new Stopwatch();
//timer.Start();
int num1 = 0;
int num2 = 0;
int answer = 0;
for (num1 = 100; num1 < 1000; num1++)
{
for (num2 = 100; num2 < 1000; num2++)
{
int x = num1 * num2;
if (isPalindrome(x))
{
if (x > answer)
{
answer = x;
}
}
}
}
//timer.Stop();
System.out.println("Answer: {0} which is made from {1}, and {2}\n\nIt took {3} seconds to find the answer."+answer+" .."+num1+".." +num2);//timer.Elapsed.ToString("ss\\.ff")); //Why are num1 and num2 showing up incorrectly?
//Console.ReadLine();
}
private static boolean isPalindrome(int x)
{
int n = x;
int rev = 0;
int digit = 0;
while (n > 0)
{
digit = n % 10;
rev = rev * 10 + digit;
n = n / 10;
if (n == rev)
{
return true;
}
}
return false;
}
}