微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

如果没有,我该如何将Case Switch转换为适当的

如何解决如果没有,我该如何将Case Switch转换为适当的

如果没有其他方式,我该如何将此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 举报,一经查实,本站将立刻删除。