本帖最後由 劉漢文 於 2013-5-18 17:13 編輯
- import java.util.Date;
- import java.util.Scanner;
- public class ch66
- {
- public static void main(String args[])
- {
- Scanner s=new Scanner(System.in);
- int answer;
- int a, b, c, d, e, f, g;
- a=(int)(Math.random()*900)+10;
- b=(int)(Math.random()*900)+10;
- c=(int)(Math.random()*900)+10;
- d=(int)(Math.random()*900)+10;
- e=(int)(Math.random()*900)+10;
- f=(int)(Math.random()*900)+10;
- g=(int)(Math.random()*900)+10;
- System.out.printf("%d-%d-%d+%d-%d-%d+%d= ",a,b,c,d,e,f,g);
- long t1=new Date().getTime();
- answer=s.nextInt();
- long t2=new Date().getTime();
- System.out.print("你總共花了"+(t2-t1)+"毫秒思考, ");
- if(answer==(a-b-c+d-e-f+g))
- {
- System.out.println("且答對了!");
- }else
- {
- System.out.println("但答錯了!");
- }
- }
- }
複製代碼 |