因为点过的不能再被点到,所以将点过的数储存在数组result中,引入布尔类型变量exist
import java.util.Random;
public class SuiJi {
public static void main(String[] args) {
int result[] = new int[3];
int count = 0;
Random ran = new Random();
int i;
while(count<3) {
int s = ran.nextInt(96);
boolean exist = true;
for(i=0;i<=count;i++) {
if(s==result[i]) {
exist =true;
break;
}
else {
exist=false;
}
}
if (exist==true) {
continue;
}
else {
result[count]=s;
count++;
}
}
for(i=0;i<result.length;i++) {
System.out.println("恭喜第"+result[i]+"位员工");}
}
}
1.循环的大括号位置要注意
2。全局变量和局部变量要注意