Java实现随机出题,10道10以内加减法计算代码实例
程序员文章站
2023-12-10 18:00:34
本文实例为大家分享了java实现随机出题,10道10以内加减法计算l的具体代码,供大家参考,具体内容如下
package com.swift;
impo...
本文实例为大家分享了java实现随机出题,10道10以内加减法计算l的具体代码,供大家参考,具体内容如下
package com.swift; import java.awt.toolkit; import java.util.scanner; public class plusquiz { public static void main(string[] args) { int i=0; int number1=0,number2=0; for(;;) { number1=(int) (math.random()*10); number2=(int) (math.random()*10); //加法部分 system.out.println("what is "+number1+"+"+number2+"?"); scanner scan=new scanner(system.in); int answer=scan.nextint(); if(answer==number1+number2) { system.out.println("√"); toolkit.getdefaulttoolkit().beep(); //system.out.println('\007'); }else { system.out.println("×"); system.out.println(number1+"+"+number2+" should be "+(number1+number2)); } //减法部分 if(number1<number2) { int temp; temp=number1; number1=number2; number2=temp; } system.out.println("what is "+number1+"-"+number2+"?"); int answer2=scan.nextint(); if(answer2==number1-number2) { system.out.println("√"); for(int time=0;time<6;time++) toolkit.getdefaulttoolkit().beep(); }else { system.out.println("×"); system.out.println(number1+"-"+number2+" should be "+(number1-number2)); } //判断加减法完成次数 i++; if(i==5) { break; } } } }
以上所述是小编给大家介绍的java实现随机出题,10道10以内加减法计算详解整合,希望对大家有所帮助