Java实现随机出题,10道10以内加减法计算代码实例
人气:0
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以内加减法计算详解整合,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对网站的支持!
您可能感兴趣的文章:
加载全部内容