Repository navigation
Expand file tree
/
Copy pathNumberSystemConverter.java
More file actions
83 lines (64 loc) · 2.59 KB
/
Copy pathNumberSystemConverter.java
File metadata and controls
83 lines (64 loc) · 2.59 KB
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import java.util.Scanner;
public class NumberSystemConverter {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
while (true) {
System.out.println("\n=================================");
System.out.println(" NUMBER SYSTEM CONVERTER");
System.out.println("=================================");
System.out.println("1. Decimal → Binary");
System.out.println("2. Decimal → Octal");
System.out.println("3. Decimal → Hexadecimal");
System.out.println("4. Convert All");
System.out.println("5. Exit");
System.out.print("\nEnter your choice: ");
int choice = sc.nextInt();
if (choice == 5) {
System.out.println("\nThank you for using the converter! 👋");
break;
}
if (choice >= 1 && choice <= 4) {
System.out.print("Enter a decimal number: ");
int number = sc.nextInt();
switch (choice) {
case 1:
System.out.println(
"Binary: " +
Integer.toBinaryString(number)
);
break;
case 2:
System.out.println(
"Octal: " +
Integer.toOctalString(number)
);
break;
case 3:
System.out.println(
"Hexadecimal: " +
Integer.toHexString(number).toUpperCase()
);
break;
case 4:
System.out.println("\nDecimal: " + number);
System.out.println(
"Binary: " +
Integer.toBinaryString(number)
);
System.out.println(
"Octal: " +
Integer.toOctalString(number)
);
System.out.println(
"Hexadecimal: " +
Integer.toHexString(number).toUpperCase()
);
break;
}
} else {
System.out.println("❌ Invalid choice!");
}
}
sc.close();
}
}