package j;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner in=new Scanner (System.in);
System.out.println("题目的数量"); int number=in.nextInt();
System.out.println("数值范围 10 空格 200 ");//先考虑整数的
int up,down;
down=in.nextInt();
up=in.nextInt(); System.out.println("打印时每行的间隔");
int between;
between=in.nextInt();
System.out.println("是否有乘除法Y/N"); String jud1,jud2,jud3;
jud1=in.next();
System.out.println("是否支持小数Y/N");
jud2=in.next();
System.out.println("加减有无负数Y/N");
jud3=in.next(); do{
int flag=2; //算式长度
int shuzi;
float shuzi2;//数字
int signal=0;//数字符号
int b; //运算符号
String Temp=new String("Y");
flag =(int)(Math.random()*4)+2;//算式长度
if(jud2.equalsIgnoreCase(Temp))//是否有小数点
{
if(jud3.equalsIgnoreCase(Temp))//是否有负数
signal=(int) (Math.random()*2); shuzi2=(float)(Math.random()*(up-down))+down;
shuzi2=(int)(shuzi2*1000);
shuzi2=shuzi2/1000;
if(signal<1)
System.out.print(shuzi2);
else
System.out.print("(-"+shuzi2+")");
}
else{
if(jud3.equalsIgnoreCase(Temp))
signal=(int) (Math.random()*2); shuzi=(int)(Math.random()*(up-down)+down);
if(signal<1)
System.out.print(shuzi);
else
System.out.print("(-"+shuzi+")"); }
//以上是第一个数
do{
if(jud1.equalsIgnoreCase(Temp))//是否有乘除
b=(int)(Math.random()*4+1);
else
b=(int)(Math.random()*2+1);
switch(b){
case 1://加
if(jud2.equalsIgnoreCase(Temp))//是否小数点
{
if(jud3.equalsIgnoreCase(Temp))//是否有负数
signal=(int) (Math.random()*2); shuzi2=(float)(Math.random()*(up-down))+down;
shuzi2=(int)(shuzi2*1000);
shuzi2=shuzi2/1000;
if(signal<1)
System.out.print("+"+shuzi2);
else
System.out.print("+"+"(-"+shuzi2+")");
}
else{ if(jud3.equalsIgnoreCase(Temp))//是否有负数
signal=(int) (Math.random()*2); shuzi=(int)(Math.random()*(up-down)+down);
if(signal<1)
System.out.print("+"+shuzi);
else
System.out.print("+"+"(-"+shuzi+")");
}
break;
case 2://减
if(jud2.equalsIgnoreCase(Temp))
{
if(jud3.equalsIgnoreCase(Temp))//是否有负数
signal=(int) (Math.random()*2); shuzi2=(float)(Math.random()*(up-down))+down;
shuzi2=(int)(shuzi2*1000);
shuzi2=shuzi2/1000;
if(signal<1)
System.out.print("-"+shuzi2);
else
System.out.print("-"+"(-"+shuzi2+")");
}
else{
if(jud3.equalsIgnoreCase(Temp))//是否有负数
signal=(int) (Math.random()*2); shuzi=(int)(Math.random()*(up-down)+down);
if(signal<1)
System.out.print("-"+shuzi);
else
System.out.print("-"+"(-"+shuzi+")");
}
break;
case 3://乘
if(jud2.equalsIgnoreCase(Temp))
{
if(jud3.equalsIgnoreCase(Temp))//是否有负数
signal=(int) (Math.random()*2); shuzi2=(float)(Math.random()*(up-down))+down;
shuzi2=(int)(shuzi2*1000);
shuzi2=shuzi2/1000;
if(signal<1)
System.out.print("*"+shuzi2);
else
System.out.print("*"+"(-"+shuzi2+")");
}
else{
if(jud3.equalsIgnoreCase(Temp))//是否有负数
signal=(int) (Math.random()*2);
shuzi=(int)(Math.random()*(up-down)+down);
if(signal<1)
System.out.print("*"+shuzi);
else
System.out.print("*"+"(-"+shuzi+")");
}
break;
case 4://除
if(jud2.equalsIgnoreCase(Temp))
{
if(jud3.equalsIgnoreCase(Temp))//是否有负数
signal=(int) (Math.random()*2); shuzi2=(float)(Math.random()*(up-down))+down;
shuzi2=(int)(shuzi2*1000);
shuzi2=shuzi2/1000;
if(signal<1)
System.out.print("/"+shuzi2);
else
System.out.print("/"+"(-"+shuzi2+")");
}
else{
if(jud3.equalsIgnoreCase(Temp))//是否有负数
signal=(int) (Math.random()*2); shuzi=(int)(Math.random()*(up-down)+down);
if(signal<1)
System.out.print("/"+shuzi);
else
System.out.print("/"+"(-"+shuzi+")");
}
break;
}
flag--;
}while(flag>0);
System.out.print("=");
number--;
for(int k=1;k<=between;k++)
System.out.println();
}while(number>0);
}
}
做了n个简单的功能,但是括号君没头绪,所以卡代码了。小小的升级了一下----
求指点……