fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. public static void main (String[] args) throws java.lang.Exception
  11. {
  12. Scanner sc = new Scanner(System.in);
  13. int t = sc.nextInt();
  14. BeingZero bz = new BeingZero();
  15. while(t--!=0) {
  16. int n = sc.nextInt();
  17. int ans = bz.reverse(n);
  18. System.out.println(ans);
  19. }
  20.  
  21. }
  22. }
  23.  
  24. class BeingZero {
  25. public int reverse(int n) {
  26. //Write your logic here
  27. int rev = 0;
  28. while(n !=0){
  29. int digit = n%10;
  30. rev = rev *10+digit;
  31. n = n/10;
  32. }
  33. return rev;
  34.  
  35. }
  36. }
Success #stdin #stdout 0.15s 56576KB
stdin
5
12345
1010
1000
-1234
-1200
stdout
54321
101
1
-4321
-21