fork(1) 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 invertir(int n){
  11. int resto;
  12. while (n>0){
  13. resto = n %10;
  14. n = n/10;
  15. System.out.print(resto);
  16. }
  17. }
  18. public static void main (String[] args) throws java.lang.Exception
  19. {
  20. Scanner scan = new Scanner(System.in);
  21. int n;
  22. System.out.println("Ingrese el numero a invertir");
  23. n = scan.nextInt();
  24. System.out.print("El numero "+n+ " invertido es ");
  25. Ideone.invertir(n);
  26.  
  27. }
  28. }
Success #stdin #stdout 0.1s 380672KB
stdin
123
stdout
Ingrese el numero a invertir
El numero 123 invertido es 321