-
Notifications
You must be signed in to change notification settings - Fork 0
/
SistemasNumericosEntradaScanner.java
31 lines (25 loc) · 1.22 KB
/
SistemasNumericosEntradaScanner.java
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
import java.util.InputMismatchException;
import java.util.Scanner;
public class SistemasNumericosEntradaScanner {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.println("Ingrese un número entero:");
// String numeroStr = scanner.nextLine();
int numeroDecimal = 0;
try {
numeroDecimal = scanner.nextInt();// Integer.parseInt(numeroStr);
} catch (InputMismatchException e){
System.out.println("Error debe ingresar un número entero!");
main(args);
System.exit(0);
}
System.out.println("numeroDecimal = " + numeroDecimal);
String resultadoBinario = "numero binario de " + numeroDecimal + " = " + Integer.toBinaryString(numeroDecimal);
String resultadoOctal = "numero octal de " + numeroDecimal + " = " + Integer.toOctalString(numeroDecimal);
String resultadoHex = "numero hexadecimal de " + numeroDecimal + " = " + Integer.toHexString(numeroDecimal);
String mensaje = resultadoBinario;
mensaje += "\n" + resultadoOctal;
mensaje += "\n" + resultadoHex;
System.out.println(mensaje);
}
}