package mmm;
import java.util.Scanner;
public class Hi{
public static void main(String args[]){
int num1, num2, result, choice;
Scanner abhi = new Scanner(System.in);
System.out.println("You Have The Following Choices:");
System.out.println("1. Addition");
System.out.println("2. Subtraction");
System.out.println("3. Multiplication");
System.out.println("4. Division ");
choice = abhi.nextInt();
System.out.println("Enter The First Number");
num1 = abhi.nextInt();
System.out.println("Enter The Second Number");
num2 = abhi.nextInt();
switch(choice){
case 1:
result = num1 + num2;
break;
case 2:
result = num1 - num2;
break;
case 3:
result = num1 * num2;
break;
case 4:
result = num1/num2;
break;
default:
System.out.println("Error");
}
System.out.println("The Result Is "+result);
}
}
它說result
沒有初始化;而我初始化了它。 我基本上哪裏錯了?我宣佈變量類型和所有,並盡我所能。我是一個小白菜,所以,請原諒我愚蠢的問題和疑問。 任何幫助,將不勝感激!爲什麼說變量沒有初始化?
哪個變量未分配?你能告訴我們輸出嗎? –
'System.out.println(「Result Is」+結果)中'result'的值是多少;'如果'switch'命中了默認情況? – bradimus
局部變量不採用默認值,並且您在默認情況下不初始化它 –