统计信息

  • 访问数:9583
  • 博客数:142
  • 建立时间:2008-01-05
  • 更新时间:2008-05-21
我叫王超然,是一名电脑爱好者,现在在新加坡留学上高一.我立志成为一名电脑人才,愿意在这里与大家一同分享我玩转电脑的心得.O-level华文考了A-One哈哈!

P6Q7

2008-04-14 22:02:13

天气: 晴朗 心情: 高兴

/*filename:P6Q7
 * Name:Wang Chaoran
 * Description:
(Counting single digits) Write a program that generates one hundred random integers
between 0 and 9 and displays the count for each number. Hint: Use (int)(Math.random() * 10)
to generate a random integer between 0 and 9. Use an array of ten integers, say counts, to store
the counts for the number of 0's, 1's, ..., 9's.
*/
class P6Q7{
  public static void main(String[] args){
    int [] counts = new int[10];
     int random =0;
    for(int i=0;i<100;i++){
    random = (int)(Math.random()*10);
    if(i%10==9)
      System.out.println(random);
    else
    System.out.print(random+" ");
    counts[random]++;
  }
    for(int i=0;i<counts.length;i++)
    System.out.println("the counts for the number of "+i+" is: "+counts[i]);
}
}
加入收藏 编辑 审核

TAG: computing

我来说两句

OPEN

Powered by X-Space 1.2 © 2001-2006 Comsenz Technology Ltd