gpt4 book ai didi

java - 找不到符号java计算代码

转载 作者:塔克拉玛干 更新时间:2023-11-03 01:44:53 25 4
gpt4 key购买 nike

<分区>

我完全是 java 菜鸟。刚刚开始。一些请帮我得到这个代码。试图编写代码来执行计算,但它显示找不到符号。

import java.util.Scanner;

public class Cal {
public static void main(String args[]) {
int a, b, r;
String op;
System.out.print("Choose one : add, sub, mul, div ");
Scanner input = new Scanner(System.in);
op = input.nextLine();
System.out.print("Enter the value : ");
Scanner val = new Scanner(System.in);
a = val.nextInt();
b = val.nextInt();
if (op == add) {
r = a + b;
System.out.println(r);
} else if (op == sub) {
r = a - b;
System.out.println(r);
} else if (op == mul) {
r = a * b;
System.out.println(r);
} else if (op == div) {
r = a / b;
System.out.println(r);
}
}
}

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com