Quiz System (Java edition)

Source: Internet
Author: User

(1) Ideas: Three methods, generate a certain number of integer problems, generate a certain number of fractional questions, functional directory. Where, using an array, the array length is the number of questions +1, each randomly generated a question and array comparison, to avoid duplication of the topic.

(2) Code:

Import Java.util.scanner;public class Test {public static void main (string[] args) {Scanner scanner=new Scanner (system.in int state = 0;while (state = = 0) {Mulu (); int num = Scanner.nextint (); if (num ==1) {System.out.println ("Number of input questions"); Suan ( Scanner.nextint ());} if (num ==2) {System.out.println ("Number of input questions"); Zsuan (Scanner.nextint ());} if (num ==3) {state = 1; System.out.println ("Has exited!! ");}}} public static void Mulu () {System.out.println ("************************"); System.out.println ("1. Integer operation"); System.out.println ("2. True fractional operation"); System.out.println ("3. Exit"); System.out.println ("************************"); SYSTEM.OUT.PRINTLN ("Please select");} public static void Suan (int num) {string[] str = new string[num+1];str[0]= "", for (int i=1;i<=num;i++) {String ss= ""; int s Tate = 0;int IntVal3 = (int) (Math.random () *4+1), int intVal1 = 0;int IntVal2 = 0;while (state = = 0) {intVal1 = (int) (Math.ran Dom () *100+1), intVal2 = (int) (Math.random () *100+1), ss = intval1+ "" +intval2;for (int j=0;j<i;j++) {if (Ss.equals (str[ I-1]) State=0;else{state=1;str [i]=intval1+ "" +intval2;}} System.out.print (i+ ","); if (intval3==1) {System.out.print (INTVAL1); System.out.print ("+"); System.out.print (INTVAL2); System.out.print ("=?"); System.out.println ();} if (intval3==2) {System.out.print (INTVAL1); System.out.print ("-"); System.out.print (INTVAL2); System.out.print ("=?"); System.out.println ();} if (intval3==3) {System.out.print (INTVAL1); System.out.print ("*"); System.out.print (INTVAL2); System.out.print ("=?"); System.out.println ();} if (intval3==4) {System.out.print (INTVAL1); System.out.print ("÷"); System.out.print (INTVAL2); System.out.print ("=?"); System.out.println ();}}} public static void Zsuan (int num) {string[] st = new string[num+1];st[0]= "", for (int i=1;i<=num;i++) {int num1 = 0;int num 2 = 0;int num3 = 0;int num4 = 0; String ss= ""; String ss1= ""; String ss2= "", int state = 0;int INTVAL3 = (int) (Math.random () *4+1), while (state = = 0) {while (num1==num2) {num1 = (int) (Math). Random () *100+1), num2 = (int) (Math.random () *100+1), if (num1<num2) {ss1=num1+ "/" +NUM2;} Else{ss1=num2+ "/" +NUM1;}} while (NUM3==NUM4) {num3 = (int) (Math.random () *100+1), num4 = (int) (Math.random () *100+1), if (NUM3&LT;NUM4) {ss2=num3+ "/ "+NUM4;} else{ss2=num4+ "/" +NUM3;}} SS =ss1+ss2;for (int j=0;j<i;j++) {if (Ss.equals (St[i-1])) state=0;else{state=1;st [I]=ss1+ss2;}}} System.out.print (i+ ","); if (intval3==1) {System.out.print (SS1); System.out.print ("+"); System.out.print (SS2); System.out.print ("=?"); System.out.println ();} if (intval3==2) {System.out.print (SS1); System.out.print ("-"); System.out.print (SS2); System.out.print ("=?"); System.out.println ();} if (intval3==3) {System.out.print (SS1); System.out.print ("*"); System.out.print (SS2); System.out.print ("=?"); System.out.println ();} if (intval3==4) {System.out.print (SS1); System.out.print ("÷"); System.out.print (SS2); System.out.print ("=?"); System.out.println ();}}}

(3) Results:

Quiz System (Java edition)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.