问题描述
如果没有其他方式,我该如何将此Case Switch转换为适当的 我的案例切换如下所示
** ***包com.company.CalculatorProject;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
boolean running = true;
Scanner scanner = new Scanner(system.in);
Calculator calculator = new Calculator();
while(running)
{
System.out.println("CHOOSE AN OPTION");
System.out.println("\t1. Add");
System.out.println("\t2. Subtract");
System.out.println("\t3. Multiply");
System.out.println("\t4. Divide");
System.out.println("\t5. Reset");
System.out.println("\t6. Quit");
System.out.print("Enter Option: ");
int choice = scanner.nextInt();
double a,b,result;
switch(choice)
{
case 1:
System.out.print("Enter first number: ");
a = scanner.nextDouble();
System.out.print("Enter second number: ");
b = scanner.nextDouble();
result = calculator.Add(a,b);
System.out.println(a + " + " + b + " = " + result);
break;
case 2:
System.out.print("Enter first number: ");
a = scanner.nextDouble();
System.out.print("Enter second number: ");
b = scanner.nextDouble();
result = calculator.Subtract(a,b);
System.out.println(a + " - " + b + " = " + result);
break;
case 3:
System.out.print("Enter first number: ");
a = scanner.nextDouble();
System.out.print("Enter second number: ");
b = scanner.nextDouble();
result = calculator.Multiply(a,b);
System.out.println(a + " * " + b + " = " + result);
break;
case 4:
System.out.print("Enter first number: ");
a = scanner.nextDouble();
System.out.print("Enter second number: ");
b = scanner.nextDouble();
result = calculator.Divide(a,b);
System.out.println(a + " / " + b + " = " + result);
break;
case 5:
System.out.print("Are you sure you want to reset? [0 for NO or 1 for YES]: ");
if(scanner.nextInt() == 1)
calculator.Reset();
break;
case 6:
System.out.print("Are you sure you want to quit? [0 for NO or 1 for YES]: ");
if(scanner.nextInt() == 1)
running = false;
break;
}
System.out.println("The calculator has performed " + calculator.GetCount() + " operations.\n");
}
}
}
如果没有其他方式,我该如何将此Case Switch转换为适当的 我的案例开关如下所示如何将案例开关转换为合适的容器 我的案例开关如下所示如何将案例开关转换为合适的容器 我的案例开关如下所示如何将案例开关转换为合适的容器 我的案例切换如下所示
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)