PackageCom.swift;ImportJava.awt.Toolkit;ImportJava.util.Scanner; Public classPlusquiz { Public Static voidMain (string[] args) {intI=0; intNumber1=0,number2=0; for(;;) {Number1=(int) (Math.random () *10); Number2=(int) (Math.random () *10); //Addition PartSystem.out.println ("What's" +number1+ "+" +number2+ "?")); Scanner Scan=NewScanner (system.in); intAnswer=Scan.nextint (); if(answer==number1+number2) {System.out.println (√); Toolkit.getdefaulttoolkit (). Beep (); //System.out.println (' \007 '); }Else{System.out.println ("X"); System.out.println (Number1+ "+" +number2+ "should be" + (number1+number2)); } //Subtraction Section if(number1<number2) { inttemp; Temp=Number1; Number1=number2; Number2=temp; } System.out.println ("What's" +number1+ "-" +number2+ "?"); intAnswer2=Scan.nextint (); if(answer2==number1-number2) {System.out.println (√); for(inttime=0;time<6;time++) Toolkit.getdefaulttoolkit (). Beep (); }Else{System.out.println ("X"); System.out.println (Number1+ "-" +number2+ "should be" + (number1-number2)); } //determine the number of add and subtract finishesi++; if(i==5) { Break; } } }}
Java implementation of random question, 10 in 10 plus subtraction calculation