-
Why JAVA is so slow?
Hi,
I'm trying to compute this problem but it take so long with java
Can anyone RUN it and show the result pls (if you have a good computer).
Code:
class CountMirror
{
public static void main(String[] args) throws Exception
{
int count = 0;
for(int j=100000000; j<=999999999; j++)
{
int num = j;
String str = Integer.toString(num);
String reStr = "";
for(int i=0; i<9; i++)
{
reStr = str.charAt(i) + reStr;
}
int revInt = Integer.parseInt(reStr);
if(revInt==j)
{
count = count + 1;
}
}
System.out.println (count);
}
}
My result until 8 are:
[CODE]x y
1 10
2 9
3 90
4 90
5 900
6 900
7 9000
8 9000
9
/CODE]
-
Heck man, your crazy... now that I have that out of my system.
You are trying to count through almost 1billion numbers. of course it will take forever. Also, you are not printing anything out in the for loop. It's not going to do what you want. Period.
-
Just try to write down your logic on a paper with the each number you want to workout in the loop.