public class DisplayDigitsSquaredReversed
1: //DisplayDigitsSquaredReversed.java
2:
3: public class DisplayDigitsSquaredReversed
4: {
5: public static void main(String[] args)
6: {
7: System.out.println("\nTesting displayDigitsReversedSquared() ...");
8: displayDigitsReversedSquared(123456);
9: System.out.println();
10: displayDigitsReversedSquared(1);
11: System.out.println();
12: displayDigitsReversedSquared(2);
13: System.out.println();
14: displayDigitsReversedSquared(13579);
15: System.out.println();
16: displayDigitsReversedSquared(86420);
17: System.out.println();
18: }
19:
20: //Displays the squares of the digits in n in the reverse of the
21: //order in which the digits appeared in n
22: public static void displayDigitsReversedSquared(int n)
23: {
24: if (n < 10)
25: System.out.print(n * n);
26: else
27: {
28: System.out.print((n % 10) * (n % 10));
29: displayDigitsReversedSquared(n / 10);
30: }
31: }
32: }