0
我最近開始學習java,我試圖編程計算器,但它給了我錯誤(我不明白爲什麼會發生)。需要幫助,在我的Java計算器
PS:對不起我的英文不好
package pkg2;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner reader = new Scanner(System.in);
System.out.println("Write a number: ");
int first = reader.nextInt();
System.out.println("Write another number: ");
int second = reader.nextInt();
System.out.println("Write an operator: ");
char operator = reader.nextInt();
if(operator == '+') {
System.out.println(first + second);
}
else if(operator == '-') {
System.out.println(first - second);
}
else if(operator == '*') {
System.out.println(first * second);
}
else if(operator == '/') {
System.out.println(first/second);
}
}
}
的錯誤是:
它給**什麼**錯誤?這是你問題中最重要的部分,並且缺失。 –
使用reader.next()。charAt(0)讀取char – piyushj
對不起,我已經編輯了帖子 – FRP7