我有「compareMethod」和while循環的問題,所以如果任何人有任何idead如何幫助我,我將不勝感激,謝謝。我將Eclipse用作Ide。java中的方法和while循環的錯誤
我想輸入三個值然後打印最小的一個。
這裏是我的代碼:
import java.util.Scanner;
public class CompareValues
{
public static void main(String[] args)
{
System.out.println();
System.out.println("The smallest number is: ");
int first;
int second;
int third;
checkMethod(first, second, third);
}
static int checkMethod(int firstNumber, int secondNumber, int thirdNumber)
{
Scanner input = new Scanner(System.in);
System.out.println("Enter three nubmers between 1 - 100: ");
firstNumber = input.nextInt();
secondNumber = input.nextInt();
thirdNumber = input.nextInt();
if ((0 < firstNumber) || secondNumber || (thirdNumber > 100))
{
System.out.println("Invalid entry: enter numbers between 1 and 100 only: ");
}
}
static int compareMethod(int first, int second, int third)
{
if ((first < second) && (first < third))
{
return first;
}
else if ((second < first) && (second < third))
{
return second;
}
else
{
return third;
}
}
}
當我整理我得到這個消息的代碼:
Exception in thread "main" java.lang.Error: Unresolved compilation problems: The local variable first may not have been initialized The local variable second may not have been initialized The local variable third may not have been initialized at CompareValues.main(CompareValues.java:11)
是什麼問題?請你也可以正確縮進代碼。 – kgautron
你有什麼問題?你能否詳細說明一下? –
哪個'while'循環? –