2 개의 숫자를 입력 할 수 있지만 "wahl"(스위치)에 정수를 입력하면 결과가 잘못됩니다.자바 계산기 스위치가 작동하지 않습니다
import java.util.Scanner;
public class taschenrechner {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
System.out.println("Bitte erste Zahl eingeben:");
int a = s.nextInt();
System.out.println("Bitte zweite Zahl eingeben:");
int b = s.nextInt();
System.out.println("1.+ \n 2.- \n 3.* \n 4. /");
int wahl = s.nextInt();
switch(wahl){
case 1:
addieren(a,b);
break;
case 2:
subtrahieren(a,b);
break;
case 3:
multiplizieren(a,b);
break;
case 4:
dividieren(a,b);
break;
}
System.out.println("Bye Bye World");
}
private static int addieren(int a, int b){
int c = a + b;
return c;
}
private static int subtrahieren(int a, int b){
int c = a - b;
return c;
}
private static int multiplizieren(int a, int b){
int c = a * b;
return c;
}
private static int dividieren(int a , int b){
int c = a/b;
return c;
}
}
일부 누수가있을 수 있습니까?
나는 이것을 자바에서 연습하기위한 메소드와 리턴 함수로하고 싶었다.
실제로하고있는 것은 무엇입니까? 반환 값'c'을 전혀 사용하지 않으므로 결과가 어떻게 잘못 될 수 있습니까? – skiwi
아무 결과도 인쇄하지 않으면 결과가 잘못되었다는 것을 어떻게 알 수 있습니까? –
어떤 결과가 표시됩니까? 매번 바이 바이 월드를 보여줄 것입니다. – Adarsh