-2

Hi everyone just had a simple quick question and would like some quick feedback. What would be a plain simple way for a beginner programmer to take for instance a 3 digit integer such as 745 and reverse it and print it out as 547? thanks in advance

  • 1
    Possible duplicate of [Java reverse int value](http://stackoverflow.com/questions/3806126/java-reverse-int-value) – mmuzahid Apr 29 '17 at 02:26
  • Not that question. It has "vandalism" problems. – Stephen C Apr 29 '17 at 02:38
  • @StephenC what do do you mean? –  Apr 29 '17 at 02:49
  • What I mean is that the linked Q was changed in a way that made its accepted answer nonsensical (and plain wrong). I have reverted the edit ... but now the Q is no longer relevant to >>this<< Q. Hopefully a moderator will sort out this mess. – Stephen C Apr 29 '17 at 02:59

2 Answers2

2

Convert your integer value to String, then using the reverse method of StringBuilder

TuyenNTA
  • 1,194
  • 1
  • 11
  • 19
1
System.out.println(new StringBuilder("745").reverse().toString());
thiagowfx
  • 4,832
  • 6
  • 37
  • 51