上午参加工程实训课,自己动手打造了一个镀锌铁盒,同时熟悉了各种工具的使用。
下午实现二位数加减乘除的程序,同时实现各种要求。
import java.util.Random; import java.util.Scanner; public class cheng { public static boolean contains(int num1, int num2, int num3, int[] a1, int[] a2, int[] a3) { for (int i = 0; i < a1.length; i++) { if ((num1 == a1[i]) && (num2 == a2[i]) && (num3 == a3[i])) { return false; } } return true; } public static boolean time1(long c, long d) { if (d - c >= 5000000) { System.out.println("时间到,结束答题"); return false; } return true; } public static boolean reduce(int num1, int num2) { return num1 >= num2; } public static boolean division(int num1, int num2) { return (num1 >= num2) && (num1 % num2 == 0); } public static boolean mul(int num1, int num2) { double b = 1000.0 / (double) (num1); return num2 < b; } public static int correct(int num1, int num2, int num3) { int b = 0; switch (num3) { case 0 -> { b = num1 + num2; break; } case 1 -> { b = num1 - num2; break; } case 2 -> { b = num1 * num2; break; } case 3 -> { b = num1 / num2; break; } } return b; } public static void main(String[] args) { int num1, num2, num3; int sum = 0; int an; Random r = new Random(); Scanner sc = new Scanner(System.in); String[] a = new String[4]; int[] a1 = new int[30]; int[] a2 = new int[30]; int[] a3 = new int[30]; int count = 0; boolean f1 = false, f2 = false, f3 = false, f4 = false; a[0] = "+"; a[1] = "-"; a[2] = "*"; a[3] = "/"; long c = System.currentTimeMillis(); System.out.println("初始时间为:" + c); while (count != 30) { long d = System.currentTimeMillis(); num1 = r.nextInt(90) + 10; num2 = r.nextInt(90) + 10; num3 = r.nextInt(4); switch (num3) { case 1 -> { f1 = reduce(num1, num2); break; } case 2 -> { f2 = mul(num1, num2); break; } case 3 -> { f3 = division(num1, num2); break; } } f4 = contains(num1, num2, num3, a1, a2, a3); if (f1 && f2 && f3 && f4) { a1[count] = num1; a2[count] = num2; a3[count] = num3; count++; System.out.println(count + "、" + num1 + a[num3] + num2 + "="); System.out.println("请输入正确答案:"); an = correct(num1, num2, num3); int answer = sc.nextInt(); System.out.println("倒计时" + (500000 - (System.currentTimeMillis() - c)) / 100 + "秒"); boolean f5 = time1(c, System.currentTimeMillis()); if (!f5) { break; } if (answer == an) { sum++; } } } System.out.println("本次一共本次答对题目 " + sum + "道,答错" + (30 - sum) + ",题目通过率为:" + (((sum * 1.0) / (30 * 1.0)) * 100 + "%")); } }
标签:9.18,return,num1,num2,num3,int,System From: https://www.cnblogs.com/zzqq1314/p/17713049.html