首页 > 代码库 > 出题系统(java版)
出题系统(java版)
(1)思路:三个方法,生成一定数量的整数题,生成一定数量的分数题,功能目录。其中,利用一个数组,数组长度为题目数量+1,每次随机生成一道题与数组比较,用来避免题目重复。
(2)代码:
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("输入题目数量"); suan(scanner.nextInt()); } if(num ==2) { System.out.println("输入题目数量"); zsuan(scanner.nextInt()); } if(num ==3) { state = 1; System.out.println("已退出!!"); } } } public static void mulu() { System.out.println("************************"); System.out.println("1.整数运算"); System.out.println("2.真分数运算"); System.out.println("3.退出"); System.out.println("************************"); System.out.println("请选择"); } public static void suan(int num) { String[] str = new String[num+1]; str[0]=""; for(int i=1;i<=num;i++) { String ss=""; int state = 0; int intVal3 = (int)(Math.random()*4+1); int intVal1 = 0; int intVal2 = 0; while(state == 0) { intVal1 = (int)(Math.random()*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 num2 = 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<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)结果:
出题系统(java版)
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。