求本题Java解法
查看原帖
求本题Java解法
815406
IntelliEnd楼主2022/12/8 15:43

本人代码如下,各位大佬看看本人代码有何问题

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        char c = sc.next().charAt(0);
        if(b == 0 && c == '/'){
            System.out.println("Divided by zero!");
        }
        if (c == '+') {
            System.out.println(a + b);
        } else if (c == '-') {
            System.out.println(a - b);
        } else if (c == '*') {
            System.out.println(a * b);
        } else if (c == '/') {
            System.out.println(a / b);
        }else if(c != '+' || c != '-' || c != '*' || c != '/'){
            System.out.println("Invalid operator!");
        }

    }
}
2022/12/8 15:43
加载中...