嘿,我刚开始Java,我想做一个简单的计算器,但是我的计算机不工作,你们能帮我吗?
这是我的程序
import java.util.Scanner;
public class Rechner {
public static void main(String[] args) {
int e = 0;
int z = 0;
char o = 0;
Scanner scan = new Scanner(System.in);
Scanner scan1 = new Scanner(System.in);
Scanner scan2 = new Scanner(System.in);
System.out.println("Wie lautet die Rechenaufgabe? : ");
e = scan.nextInt();
z = scan2.nextInt();
o = scan1.next().charAt(0);
switch(o) {
case '+' :
System.out.println("Das Ergebnis lautet: " + (e + z));
break;
case '*' :
System.out.println("Das Ergebnis lautet: " + (e * z));
break;
case '-' :
System.out.println("Das Ergebnis lautet: " + (e - z));
break;
case '/' :
System.out.println("Das Ergebnis lautet: " + (e / z));
break;
default:
System.out.println("Ungültige Eingabe");
}
scan.close();
scan1.close();
scan2.close();
}
}
当我输入例如5 * 5时,它会说:
Wie lautet die Rechenaufgabe? :
5*5
Exception in thread "main" java.util.InputMismatchException
at java.util.Scanner.throwFor(Unknown Source)
at java.util.Scanner.next(Unknown Source)
at java.util.Scanner.nextInt(Unknown Source)
at java.util.Scanner.nextInt(Unknown Source)
at Rechner.main(Rechner.java:27)
请帮助我了解我该怎么做,并且是初学者
忽略此: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa