0
一個簡單的算法有兩個類。試圖弄清楚爲什麼它不會打印任何東西。可能很明顯,但我看不到它。 該程序需要2個輸入,一個字符串和一個Int。它重複字符串int等於的次數。爲什麼這個循環不打印任何東西?
MAIN:
public class Main {
public static void main (String[]args) {
Scanner input = new Scanner(System.in);
System.out.print("Enter the string you want to repeat: ");
String str = input.nextLine();
input.nextLine();//Clear scanner memory
System.out.print("Enter the amount of times you want it to repeat: ");
int repeat = input.nextInt();
references.repeat(str, repeat);
}
}
第二類:
public void repeat(String str, int n) {
for (int repeatNum = n; repeatNum > 0; repeatNum--) {
System.out.println(str);
}
}
你輸入了什麼值?你給 – nhgrif
代碼看起來不錯 – iluxa
如果有可能,你能提供一個更完整的代碼示例(可能沒有任何增加或改變運行一個)?如果沒有提供,那麼閱讀有點困難,如果沒有它,可能會有一些細節我們無法實現。 –