Printing the digits of a number in reverse order

后端 未结 2 1280
太阳男子
太阳男子 2020-12-22 13:17

Can someone please help me solve this? The number should be variable and not constant. The output should be:

Timestamping In 6 Digit
8
5
6
3
0
1
Average In 6 Digit         


        
相关标签:
2条回答
  • 2020-12-22 13:44

    What do you really want to do? Print two integer numbers reversed? Then you should say so.

    public static String reverseDigits(int i) {
      StringBuilder sb = new StringBuilder();
      sb.append(i);
      sb.reverse();
      return sb.toString();
    }
    
    ...
    System.out.println(reverseDigits(1234567));
    ...
    
    0 讨论(0)
  • 2020-12-22 13:52

    If you just want to reverse a number then here you go

    public String reverseNum(Integer i)
    {
    return new StringBuilder(i.toString()).reverse();
    }
    
    0 讨论(0)
提交回复
热议问题