自动产生一行六位的数?(java)

来源:百度知道 编辑:UC知道 时间:2024/07/04 09:59:00
请看以下代码:我的目的是产生6位范围为1~33的数,为什么我运行后的结果
却是三位呢:比如16 28 26 ;26 11 29 。。。
我是新手,请高手们帮忙解答,谢谢!

package com.Score;
public class Score {

/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
int score;
StringBuffer sb=new StringBuffer();
for(int i=0;i<6;++i){
score=(int)(Math.random()*34);
sb.append(score).append(" ");
i++;
}
System.out.println(sb);
}

}

score=(int)(Math.random()*34);
sb.append(score).append(" ");
i++;

你把这个i++给删了

for(int i=0;i<6;++i){
这里已经自增了一次了

原来的代码: 相当于你一次把i自増2