标签:
我的队友:杜殷浩 201306114426
SiZe.java
import java.util.*; import java.util.Random; import java.text.DecimalFormat; public class SiZe { static int num_2 = 0; public static void main(String[] args) { DecimalFormat dFormat=new DecimalFormat("#.00"); while(num_2 > 5 || num_2 <= 0) { System.out.print("请输入题目的数量(题目数量最多不能超过5个): "); Scanner sc = new Scanner(System.in); num_2 = sc.nextInt(); } System.out.println("注意!除法计算结果保留两位,含四舍五入!!"); FengZhuang FZ = new FengZhuang(); } public int HuoQu() { return num_2; } }
FengZhuang.java
import java.util.Random; import java.util.Scanner; import java.text.DecimalFormat; public class FengZhuang { //static int num_1 = 0; public FengZhuang() { int num_1 = SiZe.num_2; String[] str_1 = new String[] {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9"}; String[] str_2 = new String[] { "+", "-", "*", "/"}; int index_1 = 0; int index_2 = 0; int[] a = new int[2]; double data = 0; double answer = 0; int num = 0; long t1=System.currentTimeMillis(); for(int k = 0; k < num_1; k++) { System.out.print("第"+(k+1)+"道题:"); for(int i = 0; i < 2; i++) { index_1 = new Random().nextInt(9); if(str_2[index_2].equals("/") && index_1 != 0) { while(index_1 == 0) { index_1 = new Random().nextInt(9); } } a[i] = index_1; if(i != 1) { index_2 = new Random().nextInt(4); } } ///////////// System.out.print(str_1[a[0]]+str_2[index_2]+str_1[a[1]]+"="); ///// Scanner input = new Scanner(System.in); data =input.nextDouble(); switch(index_2) { case 0: answer = a[0] + a[1]; break; case 1: answer = a[0] - a[1]; break; case 2: answer = a[0] * a[1]; break; case 3: answer = (double)a[0] / a[1]; answer = (Math.round(answer*100)/100.0); break; } if(data == answer) { System.out.println("你输入的答案正确!"); num++; } else { System.out.println("你输入的答案错误!正确答案是: "+answer); } System.out.println(); if((System.currentTimeMillis()-t1)/1000 >= 120) { System.out.println("时间已到,不能答题!"); break; } } System.out.println(num_1+"道题目,你一共答对"+num+"道题目!"); System.out.println("完成"+num+"道题目所用时间为: "+ (System.currentTimeMillis()-t1)/1000 + "秒!"); } }
标签:
原文地址:http://www.cnblogs.com/OuZeBo/p/4468925.html