码迷,mamicode.com
首页 > 其他好文 > 详细

HW4.2

时间:2016-08-13 21:02:43      阅读:141      评论:0      收藏:0      [点我收藏+]

标签:

技术分享

技术分享

 

 1 import java.util.Scanner;
 2 
 3 public class Solution
 4 {
 5     public static void main(String[] args)
 6     {
 7         Scanner input = new Scanner(System.in);
 8         int correctCount = 0;
 9         int answer = 0;
10         int number1;
11         int number2;
12 
13         long startTime = System.currentTimeMillis();
14 
15         for(int i = 0; i < 10; i++)
16         {
17             number1 = (int)(Math.random() * 15);
18             number2 = (int)(Math.random() * 15);
19             System.out.print(number1 + " + " + number2 + " = ? ");
20             answer = input.nextInt();
21             if(answer == number1 + number2)
22                 correctCount++;
23         }
24 
25         input.close();
26 
27         long endTime = System.currentTimeMillis();
28         long usedTime = (endTime - startTime) / 1000;
29 
30         System.out.println("You have " + correctCount + " answers");
31         System.out.println("Used time: " + usedTime);
32     }
33 }

 

HW4.2

标签:

原文地址:http://www.cnblogs.com/wood-python/p/5768765.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!