首页 > 代码库 > 四则运算
四则运算
import java.util.Random; import java.util.Scanner; public class qq { public static void main(String[] args) { int e = 0, r = 0; System.out.println("欢迎来到四则运算测试软件!"); System.out.println("做题前请认真读题,祝您考试愉快!"); Random r1 = new Random(); for (int i = 0; i < 7; i++) { int m, n; int a, b, c; m = r1.nextInt() % 10; n = m % 4; switch (n) { case 0: a = new Random().nextInt((int) Math.pow(10, 2)) + 1; b = new Random().nextInt((int) Math.pow(10, 2)) + 1; System.out.println(a + "+" + "" + b + "=?"); Scanner x1 = new Scanner(System.in); c = x1.nextInt(); if (c != a + b) { e++; System.out.println("回答错误!!"); } else { r++; System.out.println("回答正确!!"); } break; case 1: a = new Random().nextInt((int) Math.pow(10, 2)) + 1; b = new Random().nextInt((int) Math.pow(10, 2)) + 1; System.out.println(a + "-" + " " + b + " =?"); Scanner x2 = new Scanner(System.in); c = x2.nextInt(); if (c != a - b) { e++; System.out.println("回答错误!!"); } else { r++; System.out.println("回答正确!!"); } break; case 2: a = new Random().nextInt((int) Math.pow(10, 2)) + 1; b = new Random().nextInt((int) Math.pow(10, 2)) + 1; System.out.println(a + "*" + " " + b + " " + "=?"); Scanner y1 = new Scanner(System.in); c = y1.nextInt(); if (c != a * b) { e++; System.out.println("回答错误!!"); } else { r++; System.out.println("回答正确!!"); } break; case 3: double d; a = new Random().nextInt((int) Math.pow(10, 2)) + 1; b = new Random().nextInt((int) Math.pow(10, 2)) + 1; if (b == 0) b++; System.out.println(a + "/" + " " + b + " " + "=?"); Scanner y2 = new Scanner(System.in); d = y2.nextDouble(); if (d != (a / b) / 1.00) { e++; System.out.println("回答错误!!"); } else { r++; System.out.println("回答正确!!"); } break; } } System.out.println("考试结束!!"); System.out.println("您一共做了:" + (r + e) + "道题目,其中正确的有" + r + "道,错误的有" + e + "道!"); } }
四则运算
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。