Jcreator表示如果(big%2 == 0)變量big可能未被初始化。 然後我將「int big」更改爲「int big = 0」,它可以工作。我在if(big%2 == 0)之前的前兩個if語句中初始化爲什麼會發生這種情況?Java變量初始化和if語句
import java.util.Scanner;
public class Large
{
public static void main(String[]args)
{
Scanner in=new Scanner(System.in);
int number1,number2;
int big;
System.out.println("Enter 2 values");
number1=in.nextInt();
number2=in.nextInt();
if(number1>number2)
big=number1;
if(number2>=number1)
big=number2;
if(big%2==0)
System.out.println("even");
if(big%2==1)
System.out.println("odd");
}
}
非常感謝你 – 3pique