📄 switchtest3.java
字号:
class SwitchTest3
{ public static void main(String args[])
{ System.out.println("1000个随机数(1_6)产生的概率::\n");
int i=1,c1=0,c2=0,c3=0,c4=0,c5=0,c6=0,c=0;
while(i<=1000)
{ int x=(int)(Math.random()*6)+1; // 产生[1_6]区间随机整数
switch(x)
{
case 1: c1+=1; break;
case 2: c2+=1; break;
case 3: c3+=1; break;
case 4: c4+=1; break;
case 5: c5+=1; break;
case 6: c6+=1; break;
default: c+=1; break;
}
i=i+1;
}
System.out.println("产生1的次数:"+c1);
System.out.println("产生2的次数:"+c2);
System.out.println("产生3的次数:"+c3);
System.out.println("产生4的次数:"+c4);
System.out.println("产生5的次数:"+c5);
System.out.println("产生6的次数:"+c6);
System.out.println("其他数不可能产生:"+c);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -