以相反的顺序打印数字的数字

时间:2010-12-26 10:30:01

标签: java number-formatting

有人可以帮我解决这个问题吗?数字应该是可变的而不是常数。 输出应为:

Timestamping In 6 Digit
8
5
6
3
0
1
Average In 6 Digit
9
8
7
6
5
2
class Timestamp1 extends Average1
{
  public static void main (String args[]) {

    int i = 103658;
    int j = 10;
    int k = i % j;
    System.out.println(" Timestamping In 6 Digit " );
    System.out.println(" " + k);

    int o = 10365;
    int p = 10;
    int q = o % p;
    System.out.println(" " + q);

    int l = 1036;
    int m = 10;
    int n = l % m;
    System.out.println(" " + n);

    int r = 103;
    int s = 10;
    int t = r % s;
    System.out.println(" " + t);

    int u = 10;
    int v = 10;
    int w = u % v;
    System.out.println(" " + w);

    int x = 1;
    int y = 10;
    int z = x % y;
    System.out.println(" " + z);




class Average1 extends Timestamp1 {

  public void main() {

    int i = 256789;
    int j = 10;
    int k = i % j;
    System.out.println(" Average In 6 Digit ");
    System.out.println(" " + k);

    int o = 25678;
    int p = 10;
    int q = o % p;
    System.out.println(" " + q);

    int l = 2567;
    int m = 10;
    int n = l % m;
    System.out.println(" " + n);

    int r = 256;
    int s = 10;
    int t = r % s;
    System.out.println(" " + t);

    int u = 25;
    int v = 10;
    int w = u % v;
    System.out.println(" " + w);

    int x = 2;
    int y = 10;
    int z = x % y;
    System.out.println(" " + z);
  }


}
}
}

2 个答案:

答案 0 :(得分:7)

如果您只想撤消一个号码,那么请转到

public String reverseNum(Integer i)
{
return new StringBuilder(i.toString()).reverse();
}

答案 1 :(得分:3)

你真的想做什么?打印两个整数反转?那你应该这么说。

public static String reverseDigits(int i) {
  StringBuilder sb = new StringBuilder();
  sb.append(i);
  sb.reverse();
  return sb.toString();
}

...
System.out.println(reverseDigits(1234567));
...