import java.util.Scanner;
//file FR.java : FowardReverse - Development
public class FR {
public static void main(String[] args) {
//int count, number;
//System.out.println("Enter a number");
//Scanner keyboard = new Scanner(System.in);
//number = keyboard.nextInt();
//count = 1;
//while (count <= number) {
// System.out.print(count + ", ");
// count++;
// }
//System.out.println();
//System.out.println("Buckle my shoe.");
int tt, th, h, t, o;
int forward, times4, reverse;
// loop through all numbers from 10,000 to 99,999 looking for a number
// that when multiplied by 4, is the reverse of that number
for (tt = 1; tt <= 9; tt++) { // start with 1 to not have any leading zeros
System.out.println("Searching through the " + (tt * 10000) + "s...");
for (th = 0; th <= 9; th++) {
System.out.println("...Searching through the " + ((tt*10+th)* 1000) + "s...");
for (h = 0; h<= 9; h++)
for (t = 0; t <= 9 ; t++)
for (o = 1; o<=9; o++) { // o becomes high digit reversed, can not be 0
forward = tt * 10000 +
th * 1000 +
h * 100 +
t * 10 +
o;
times4 = forward * 4;
reverse = o * 10000 +
t * 1000 +
h * 100 +
th * 10 +
tt;
if (reverse == times4) {
// output
System.out.println( forward + " times 4 = " + times4 +
" which is the reverse of " + forward + "." );
// now jump out of all loops
tt = th = h = t = o = 100; // kills all of the loops
}
else { if (forward == 21978) {
System.out.println( forward + " times 4 = " + times4 +
" which is the reverse of " + forward + "." +
" reverse = " + reverse);
tt = th = h = t = o = 100; // kills all of the loops
}
}
} // end looping through numbers 10,000 to 99,999
} // loop through 1000s
} // loop through 10,000s
} // main
} // class WhileDemo
|