lqd*_*qdc 3 java loops while-loop
在这个程序中,内循环生成100个随机数,然后在随机数为7时停止生成它们.外循环重复内循环100次.
为什么我的外循环不能重做内循环?
似乎它只做过一次.
package test;
public class Loops {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
int i = 0;
int sum = 0;
int counter = 0;
String randomNumberList = " ";
int c = 0;
while (c != 100){
while (i != 7) {
i = (int) (101 * Math.random());
sum += i;
++counter;
randomNumberList += " " + i;
}
System.out.print("\n loop repeated" + counter+ " times and generated these numbers: " + randomNumberList);
++c;
}
}
}
Run Code Online (Sandbox Code Playgroud)