【发布时间】:2016-11-09 02:18:03
【问题描述】:
我想打印的星星数量等于给定数字 1 到 6 的滚动次数。然后把它放到一个数组中,这样我就可以在System.out 的中间打印给定数量的星星。
它看起来像这样 [1] ******************* 19
我这里已经有了基本代码
import java.util.Random;
public class Program7 {
public static void main(String[] args) {
Random ran = new Random();
int [] timesRolled = new int[7];
for (int i=0;i<100;i++){
int die= ran.nextInt(6)+1;
if (die==1){
timesRolled [1]++;
System.out.print("*");
}
if (die==2){
timesRolled [2]++;
System.out.print("*");
}
if (die==3){
timesRolled [3]++;
System.out.print("*");
}
if (die==4){
timesRolled [4]++;
System.out.print("*");
}
if (die==5){
timesRolled [5]++;
System.out.print("*");
}
if (die==6){
timesRolled [6]++;
System.out.print("*");
}
}
System.out.println("[1]" + "\t" + here is where i want the stars + timesRolled [1]);
System.out.println("[2]" + "\t" + timesRolled [2]);
System.out.println("[3]" + "\t" + timesRolled [3]);
System.out.println("[4]" + "\t" + timesRolled [4]);
System.out.println("[5]" + "\t" + timesRolled [5]);
System.out.println("[6]" + "\t" + timesRolled [6]);
}
}
【问题讨论】: