int j = 1;
for (int i = 0; i < 99; i++)
{
if (j % 101 != 0) // if 1st 2 and last 2 digit are same, it skips
System.out.format("%04d\n", j*11);
j = ((j + 1) % 10) + (((j + 1) / 10 + j/100)%10) * 100;
System.out.println(j);
}
__________________________________________________________________________________
if (i == j)
continue; // skip the operation when i = j since first 2 digit and last 2 digit are different
int value = Integer.valueOf(""+i+i+j+j).intValue(); // "" to make it into a string, intValue() to return the value back to int
double computeValue = Math.sqrt(value); // this uses the Math class to do a square root
if (computeValue%1 == 0.0) // %1 will change all the value to be < 1, leaving them with their decimal
{
if (computeValue < 1000) // so it will displayed at least 0011 and so.
{
System.out.println("The plate number is: 00" + (int)computeValue); // printing the value if it's 0.0, since integer decimal point will be 0
}
else
{
System.out.println("The plate number is: " + (int)computeValue);
}
}
The difference between 2 code... Well mine sucks more, mine is the bottom one, look how much many line I used to solve his few lines problem -.- Although the top code is incompleted, but adding a few more lines can be completed. The german online friend of mine is so good in maths that he can come up with that long formula to shorten one for loop and not only that, his formula doesn't needs to change here and there like mine, which need to change it to a string then back to a integer -.- That makes his code so short, like a good programmer -.-
And my code, is not fully written by myself lol. He taught me how to use some of the codes, like "continue" and helped me with the API usage for changing to integer value then back to integer value. I can say this 3 lines of important code is his...
if (i == j)
continue;
int value = Integer.valueOf(""+i+i+j+j).intValue();
Rofl. I learnt alot of programming stuffs today, and the format class...
Well I sucks at OOPG, realising how I can't cope with all the lessons today, I am getting worried for my GPA this semester... I am feeling totally lost on most of the lessons lol.
Shall get some sleep now @_@
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment