自动出题抽取系统java_出题系统(java版)

  • Post author:
  • Post category: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

{

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

{

ss1=num1+”/”+num2;

}

else

{

ss1=num2+”/”+num1;

}

}

while(num3==num4)

{

num3 = (int)(Math.random()*100+1);num4 = (int)(Math.random()*100+1);

if(num3

{

ss2=num3+”/”+num4;

}

else

{

ss2=num4+”/”+num3;

}

}

ss =ss1+ss2;

for(int j=0;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)结果:

0df4528c08995d47a8175f852fab18d3.png

fdb57070f789015fdfa8ef3095f2843c.png

3219d6264533ba55a076de669dbf8aa1.png



版权声明:本文为weixin_29313547原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。