首页 > 代码库 > 结对合作 出题并判断对错
结对合作 出题并判断对错
1 package tools; 2 3 import java.util.Random; 4 import java.util.Scanner; 5 6 public class problem { 7 8 public static void main(String[] args) { 9 /**10 * 一共循环10次。11 */12 int rightNum = 0;//正确次数13 int wrongNum = 0;//错误次数14 for (int i =1; i <= 10; i++) {15 System.out.println("请计算第" + i + "道题:");// 做到第几题,循环输出16 int number1 =(int) (Math.random() * 10);17 int number2 =(int) (Math.random() * 10);18 Random num = new Random();// 生成随机运算符19 int index = num.nextInt(3) + 1;20 char[] fuhaos = { ‘+‘, ‘-‘, ‘*‘, ‘/‘ };21 String fuhao = String.valueOf(fuhaos[index]);22 Scanner scan = new Scanner(System.in);23 if (fuhao.equals("+")) { // 进行加法运算24 System.out.println(number1 + "+" + number2 + "=");25 int input = scan.nextInt();26 int sum = number1 + number2;27 if (sum==input) {28 System.out.println("正确");29 rightNum++;30 } else {31 System.out.println("错误");32 wrongNum++;33 }34 System.out.println("正确答案是:" + sum);35 }else if (fuhao.equals("-")) { // 进行减法运算36 System.out.println(number1 + "-" + number2 + "=");37 int input = scan.nextInt();38 int sum = number1 - number2;39 if (sum==input) {40 System.out.println("正确");41 rightNum++;42 } else {43 System.out.println("错误");44 wrongNum++;45 }46 System.out.println("正确答案是:" + sum);47 }else if (fuhao.equals("*")) { // 进行乘法运算48 System.out.println(number1 + "*" +number2 + "=");49 int input = scan.nextInt();50 int sum = number1 * number2;51 if (sum==input) {52 System.out.println("正确");53 rightNum++;54 } else {55 System.out.println("错误");56 wrongNum++;57 }58 System.out.println("正确答案是:" + sum);59 }else { // 进行除法运算60 System.out.println(number1 + "/" + number2 + "=");61 int input = scan.nextInt();62 int sum = number1 / number2;63 if (sum==input) {64 System.out.println("正确");65 rightNum++;66 } else {67 System.out.println("错误");68 wrongNum++;69 }70 System.out.println("正确答案是:" + sum);71 }72 }73 System.out.println("做对" + rightNum + "题");74 System.out.println("做错" + wrongNum + "题");75 }76 }
结对组合:林莉 和 宫丽君
结对合作 出题并判断对错
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。