試圖進一步我的循環理解,我發現一些問題在線,我試圖完成,但我被困在第二個最後一個。循環,隨機數發生器,然後檢查器
原始問題是:
loop4(int val)。此方法使用循環(for或while?)來執行以下操作。生成1到10之間的隨機數(包括1和10)10次,並計算val生成次數,然後打印出該數字。
我已經設法到目前爲止做:
public int Loop4(int val){
for(int i = Math.random()*10; i<= 10; val!=0){
if (i == val) {
System.out.println(//I cannot for the life of me think of how I could constantly increment a +1 to this value because I only want to end up with 1 number in the end)
}
}
}
你卡在哪一部分? – 2014-10-20 19:40:03
提示:您需要在循環外打印。你需要一個計數器變量。 – 2014-10-20 19:40:53
val!= 0 - 這是做什麼的? – Victor2748 2014-10-20 19:42:09