我在我的第二個方法很難的輸出模式的方法,該方法聲明爲: public static void displayOutput(int loopCount)
的方法從main()
調用,並傳遞其確定重複的有效的輸入值。該方法僅顯示輸出模式並不返回任何內容。每第3行顯示一個空格和3個星號調用僅顯示
我知道我沒有撥打main()
中的每個方法,我知道displayOutput(int loopCout)
是錯誤的。
有人可以向我解釋這個或使用一個有助於編寫程序的例子嗎?
public static void main(String[] args) {
int repeat;
Scanner goGet = new Scanner(System.in);
repeat = getValidValue(goGet); //Uncompilable source code -Erroneous sym type
displayOutput(repeat);
}
public static int getValidValue() {
int input;
do {
Scanner getInfo = new Scanner(System.in);
System.out.print("Enter an integer Greater than zero: --> ");
input = getInfo.nextInt();
} while (input <= 0);
return input;
}
public static int displayOutput(int loopCount) {
int i;
for (i = 0; i < loopCount; i++) {
System.out.print("The semester is ending soon. ");
System.out.print("The semester is ending soon. ");
System.out.print("The semester is ending soon.*** ");
}
return loopCount;
}
你在問一個編譯錯誤。但顯然,你沒有閱讀錯誤。或者至少你沒有認爲它有用,因爲你還沒有發佈它。閱讀。它會告訴你到底發生了什麼問題,以及在哪裏。像「method getValidValue()」之類的東西不能用類型爲java.util.Scanner的參數調用。爲什麼?因爲getValidValue()不帶任何參數,但在調用它時試圖傳遞一個參數。 –