自动出题系统新的要求: 可以控制下列参数: 是否有乘除法; 是否有括号(最多可以支持十个数参与计算); 数值范围; 加减有无负数,除法有无余数。
代码行数:242行
源代码:
import java.*;
import java.util.*;
public class Yunsuan01 {
public static void main(String args[])
{
Scanner scan;
scan = new Scanner(System.in);
int flag;//标志
int max;//最大值范围
int ysf;//运算符
int num;//数量
int i = 0;
char[] ch = new char[4];
ch[0] = '+';
ch[1] = '-';
ch[2] = '*';
ch[3] = '/';
String[] str = new String[200];
str[0] = null;
String s = null;
System.out.println("请输入你需要的题目形式:1、整数类型 2、分数类型");
flag = scan.nextInt();
int a,b,a1,b1;
double A,B,A1,B1;
if(flag == 1)
{
System.out.println("请输入您希望的最大数值范围:");
max = scan.nextInt();
System.out.println("请输入题目的数量:");
num = scan.nextInt();
while(num > 0)
{
a = (int)(Math.random()*max);
b = (int)(Math.random()*max) + 1;
ysf = (int)(Math.random()*4);
s = a + " " + ch[ysf] + " " + b + " =";
if(Check(str,s,i) != 1)
{
str[i] = s;
System.out.print(str[i]);
i ++;
}
if(ysf == 0)
{
System.out.println(intjia(a,b));
}
if(ysf == 1)
{
System.out.println(intjian(a,b));
}
if(ysf == 2)
{
System.out.println(intcheng(a,b));
}
if(ysf == 3)
{
System.out.println(intchu(a,b));
}
}
}
int flagA = 0;
int flagB = 0;
if(flag == 2)
{
System.out.println("请输入题目的数量:");
num = scan.nextInt();
for(int j = 0;i < num;i ++)
{
flagA = SuiJileixing();
flagB = SuiJileixing();
if(flagA == 1 && flagB == 0)
{
a = SuiJi1();
b = SuiJi1();
b1 = SuiJi1() + 1;
if(b < b1)
{
b1= b;
}
else
{
b1 = b1 + b;
}
ysf = SuiJiyunsuanfu();
s = a + " " + ch[ysf] + " (" + b + "/" + b1 + ") = ";
if(Check(str,s,i) != 1)
{
str[i] = s;
System.out.print(str[i]);
A = (double)a;
B = (double)b;
B1 = (double)b1;
show(A,B/B1,ysf);
i ++;
}
}
else if(flagA == 0 && flagB == 1)
{
a = SuiJi1();
a1 = SuiJi1() + 1;
b = SuiJi1();
if(a > a1)
{
a1 = a + a1;
}
ysf = SuiJiyunsuanfu();
s = "(" + a + "/" + a1 + ") " + ch[ysf] + " " + b + " = ";
if(Check(str,s,i) != 1)
{
str[i] = s;
System.out.print(str[i]);
A = (double)a;
A1 = (double)a1;
B = (double)b;
show(A/A1,B,ysf);
i ++;
}
}
else
{
a = SuiJi1();
a1 = SuiJi1() + 1;
b = SuiJi1();
b1 = SuiJi1() + 1;
if(a > a1)
{
a1 = a + a1;
}
if(b > b1)
{
b1 = b + b1;
}
ysf = SuiJiyunsuanfu();
s = "(" + a + "/" + a1 + ") " + ch[ysf] + " " + b + "/" + b1 + " = ";
if(Check(str,s,i) != 1)
{
str[i] = s;
System.out.print(str[i]);
A = (double)a;
A1 = (double)a1;
B = (double)b;
B1 = (double)b1;
show(a/a1,b/b1,ysf);
i ++;
}
}
}
}
}
public static int Check(String s[],String str,int ss)
{
int qqq = 0;
for(int i = 0;i < ss;i ++)
{
if(str.equals(s[ss]))
{
qqq = 1;
break;
}
}
return qqq;
}
//整数加法
public static int intjia(int a,int b)
{
int c;
c = a + b;
return c;
}
//整数减法
public static int intjian(int a,int b)
{
int c;
c = a + b;
return c;
}
//整数乘法
public static int intcheng(int a,int b)
{
int c;
c = a * b;
return c;
}
//整数除法
public static int intchu(int a,int b)
{
int c;
c = a / b;
return c;
}
public static int SuiJileixing()
{
int flag = (int)(Math.random()*2);
return flag;
}
public static int SuiJi1()
{
int a;
a = (int)(Math.random()*100);
return a;
}
public static int SuiJiyunsuanfu()
{
int a;
a = (int) (Math.random()*4);
return a;
}
public static void show(double a,double b,int k)
{
double c ;
if(k == 0)
{
c = a + b;
System.out.println((int)c);
}
if(k == 1)
{
c = (int) (a - b);
System.out.println((int)c);
}
if(k == 2)
{
c = (int) (a * b);
System.out.println((int)c);
}
if(k == 3)
{
c = (int) (a / b);
System.out.println((int)c);
}
}
}