-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNewClass.java
More file actions
37 lines (20 loc) · 776 Bytes
/
Copy pathNewClass.java
File metadata and controls
37 lines (20 loc) · 776 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package Invertir_numero;
import java.util.Scanner;
public class NewClass {
public static void main(String[] args) {
Scanner sn = new Scanner(System.in);
System.out.println("Ingrese el número a invertir");
int a = sn.nextInt();
int b = a;
int digitos = (int)(Math.log10(b)+1);
int c = digitos-1;
System.out.println(InvertirNum(a, c));
}
public static int InvertirNum(int num, int pos){
if (num < 10 ) {
return num;
}else{
return (num % 10) * (int) Math.pow(10, pos) + (InvertirNum(num/10, pos-1));
}
}
}