2017-11-25 222 views
-1

我在我的第二個方法很難的輸出模式的方法,該方法聲明爲: 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; 
} 
+0

你在問一個編譯錯誤。但顯然,你沒有閱讀錯誤。或者至少你沒有認爲它有用,因爲你還沒有發佈它。閱讀。它會告訴你到底發生了什麼問題,以及在哪裏。像「method getValidValue()」之類的東西不能用類型爲java.util.Scanner的參數調用。爲什麼?因爲getValidValue()不帶任何參數,但在調用它時試圖傳遞一個參數。 –

回答

0

getValidValue()這種方法不使用參數 但同時稱這是你通過一個參數。這是導致錯誤的原因。

要麼改變這種方法的原型,以便它需要的參數

public static int getValidValue(Scanner obj) 

或 簡單地從方法調用

repeat = getValidValue(); 
1

你是值傳遞給方法getValidValue刪除參數哪些沒有任何價值。

另外displayOutput正在返回loopcount,但你沒有在任何地方捕捉它,所以在星號之後它不顯示任何東西。