Java_CH11_HW1

import java.util.*;

public class Java_CH11_HW1
{

 public static void main(String[] args)
 {
  // TODO 自動產生的方法 Stub
  Random random = new Random();
  Scanner scan = new Scanner(System.in);
  System.out.print("輸入次數:");
  int num = scan.nextInt();
  Hashtable<String, Integer> table = new Hashtable<String, Integer>();
  String[] days = {"星期一", "星期二", "星期三", "星期四", "星期五", "星期六", "星期天"};
  int temp;
  for (int i = 0; i < num; i++)
  {
   temp = (random.nextInt(6) + 1) + (random.nextInt(6) + 1);
   System.out.print(temp + "\t");
   table.put(days[i], temp);
  }
  System.out.println("");
  for (Map.Entry<String, Integer> item : table.entrySet())
   System.out.println(
     String.format("%s %d", item.getKey(), item.getValue()));
  System.out.println(table.toString());
  if (table.get("星期三") != 11)
   table.put("星期三", 11);
  System.out.println(table.toString());
 }

}

留言

這個網誌中的熱門文章

C# 井字遊戲