import java.lang.Integer;
import java.util.Scanner;
public class Jsq {
public static void main(String args[]) {
while (true) {
Menu a = new Menu();
a.showMenuInfo();
a.showMenuFunc();
}
}
}
class Jisuanqi {
private String s;
public static void tishi1(String ch) {
System.out.print("请输入一个" + ch + "进制数:");
}
public void jinggao(String ch) {
System.err.println("输入有误!您必须输入一个" + ch + "进制数。");
}
public void Two_Eight() {
String m = null;
System.out.println();
System.out.println("二进制——>八进制:");
System.out.println();
tishi1("二");
try {
Scanner sc = new Scanner(System.in);
s = sc.nextLine();
m = Integer.toString(Integer.parseInt(s, 2), 8);
System.out.println("转换结果为:" + m);
} catch (Exception e) {
jinggao("二");
}
}
public void Two_Ten() {
int m = 0;
System.out.println();
System.out.println("二进制——>十进制:");
System.out.println();
tishi1("二");
try {
Scanner sc = new Scanner(System.in);
s = sc.nextLine();
m = Integer.parseInt(s, 2);
System.out.println("转换结果为:" + m);
} catch (Exception e) {
jinggao("二");
}
}
public void Two_Sixteen() {
String m = null;
System.out.println();
System.out.println("二进制——>十六进制:");
System.out.println();
tishi1("二");
try {
Scanner sc = new Scanner(System.in);
s = sc.nextLine();
m = Integer.toString(Integer.parseInt(s, 2), 16);
System.out.println("转换结果为:" + m);
} catch (Exception e) {
jinggao("二");
}
}
public void Eight_Two() {
String m = null;
System.out.println();
System.out.println("八进制——>二进制:");
System.out.println();
tishi1("八");
try {
Scanner sc = new Scanner(System.in);
s = sc.nextLine();
m = Integer.toString(Integer.parseInt(s, 8), 2);
System.out.println("转换结果为:" + m);
} catch (Exception e) {
jinggao("八");
}
}
public void Eight_Ten() {
int m = 0;
System.out.println();
System.out.println("八进制——>十进制:");
System.out.println();
tishi1("八");
try {
Scanner sc = new Scanner(System.in);
s = sc.nextLine();
m = Integer.parseInt(s, 8);
System.out.println("转换结果为:" + m);
} catch (Exception e) {
jinggao("八");
}
}
public void Eight_Sixteen() {
String m = null;
System.out.println();
System.out.println("八进制——>十六进制:");
System.out.println();
tishi1("八");
try {
Scanner sc = new Scanner(System.in);
s = sc.nextLine();
m = Integer.toString(Integer.parseInt(s, 8), 16);
System.out.println("转换结果为:" + m);
} catch (Exception e) {
jinggao("八");
}
}
public void Ten_Two() {
String m = null;
System.out.println();
System.out.println("十进制——>二进制:");
System.out.println();
tishi1("十");
try {
Scanner sc = new Scanner(System.in);
s = sc.nextLine();
m = Integer.toString(Integer.parseInt(s, 10), 2);
System.out.println("转换结果为:" + m);
} catch (Exception e) {
jinggao("十");
}
}
public void Ten_Eight() {
String m = null;
System.out.println();
System.out.println("十进制——>八进制:");
System.out.println();
tishi1("十");
try {
Scanner sc = new Scanner(System.in);
s = sc.nextLine();
m = Integer.toString(Integer.parseInt(s, 10), 8);
System.out.println("转换结果为:" + m);
} catch (Exception e) {
jinggao("十");
}
}
public void Ten_Sixteen() {
String m = null;
System.out.println();
System.out.println("十进制——>十六进制:");
System.out.println();
tishi1("十");
try {
Scanner sc = new Scanner(System.in);
s = sc.nextLine();
m = Integer.toString(Integer.parseInt(s, 10), 16);
System.out.println("转换结果为:" + m);
} catch (Exception e) {
jinggao("十");
}
}
public void Sixteen_Two() {
String m = null;
System.out.println();
System.out.println("十六进制——>二进制:");
System.out.println();
tishi1("十六");
try {
Scanner sc = new Scanner(System.in);
s = sc.nextLine();
m = Integer.toString(Integer.parseInt(s, 16), 2);
System.out.println("转换结果为:" + m);
} catch (Exception e) {
jinggao("十六");
}
}
public void Sixteen_Eight() {
String m = null;
System.out.println();
System.out.println("十六进制——>八进制:");
System.out.println();
tishi1("十六");
try {
Scanner sc = new Scanner(System.in);
s = sc.nextLine();
m = Integer.toString(Integer.parseInt(s, 16), 8);
System.out.println("转换结果为:" + m);
} catch (Exception e) {
jinggao("十六");
}
}
public void Sixteen_Ten() {
int m = 0;
System.out.println();
System.out.println("十六进制——>十进制:");
System.out.println();
tishi1("十六");
try {
Scanner sc = new Scanner(System.in);
s = sc.nextLine();
m = Integer.parseInt(s, 16);
System.out.println("转换结果为:" + m);
} catch (Exception e) {
jinggao("十六");
}
}
}
class Menu {
private boolean flag = true;
Jisuanqi J = new Jisuanqi();
public void showMenuInfo() {
System.out.println();
System.out.println(" ★欢迎进入★");
System.out.println();
System.out.println(" ***************************************************");
System.out.println(" * *********************************************** *");
System.out.println(" * * * *");
System.out.println(" * * 数制转换计算器 * *");
System.out.println(" * * * *");
System.out.println(" * * ● 1:二进制数转化为八进制 * *");
System.out.println(" * * ● 2:二进制数转化为十进制 * *");
System.out.println(" * * ● 3:二进制数转化为十六进制 * *");
System.out.println(" * * ● 4:八进制数转化为二进制 * *");
System.out.println(" * * ● 5:八进制数转化为十进制 * *");
System.out.println(" * * ● 6:八进制数转化为十六进制 * *");
System.out.println(" * * ● 7:十进制数转化为二进制 * *");
System.out.println(" * * ● 8:十进制数转化为八进制 * *");
System.out.println(" * * ● 9:十进制数转化为十六进制 * *");
System.out.println(" * * ●10:十六进制数转化为二进制 * *");
System.out.println(" * * ●11:十六进制数转化为八进制 * *");
System.out.println(" * * ●12:十六进制数转化为十进制 * *");
System.out.println(" * * ● 0:退出 * *");
System.out.println(" * * * *");
System.out.println(" * *********************************************** *");
System.out.println(" ***************************************************");
}
public void askUser() {
char c;
System.out.print("\n是否继续?(Y/N):");
Scanner sc = new Scanner(System.in);
c = sc.nextLine().charAt(0);
if (c == 'y' || c == 'Y') {
flag = true;
} else if (c == 'n' || c == 'N') {
flag = false;
} else {
System.out.println("非法输入!");
flag = false;
}
}
public void showMenuFunc() {
int n = 0;
System.out.print(" 请选择(0——12):");
try {
Scanner sc = new Scanner(System.in);
n = sc.nextInt();
} catch (Exception e) {
System.err.println("输入有误!请您重新选择。");
flag = false;
}
while (flag) {
switch (n) {
case 1:
J.Two_Eight();
askUser();
break;
case 2:
J.Two_Ten();
askUser();
break;
case 3:
J.Two_Sixteen();
askUser();
break;
case 4:
J.Eight_Tw