package size; import java.util.Random; import java.util.Scanner; public class size { public static void main(String[] args){ Random rand=new Random(); size b=new size(); System.out.println("请选择:1:2位数运算2:多位数运算"); Scanner input1=new Scanner(System.in); int c=input1.nextInt(); if(c==1) { System.out.println("请选择出题数量:"); Scanner input6=new Scanner(System.in); int c5=input6.nextInt(); System.out.println("请输入数值范围(最大值)"); Scanner input3=new Scanner(System.in); int c2=input3.nextInt(); System.out.println("请选择:1:有乘除法2:无乘除法"); Scanner input2=new Scanner(System.in); int c1=input2.nextInt(); System.out.println("请选择1:加减有负数2:加减无负数"); Scanner input4=new Scanner(System.in); int c3=input4.nextInt(); System.out.println("请选择:1.除法有余数2.除法无余数"); Scanner input5=new Scanner(System.in); int c4=input5.nextInt(); for(int m=0;m<c5;m++) { char[] a1={'+','-','*','/'}; int a=(int)(Math.random()*4); if(c1==1)//有乘除法 { if(c3==1&&c4==1)//有负数,有余数 { if(a1[a]=='+') { b.add(c2); } else if(a1[a]=='-') { b.jian2(c2); } else if(a1[a]=='*') { b.chen(c2); } else if(a1[a]=='/') { b.chu1(c2); } } else if(c3==1&&c4==2)//有负数,无余数 { if(a1[a]=='+') { b.add(c2); } else if(a1[a]=='-') { b.jian2(c2); } else if(a1[a]=='*') { b.chen(c2); } else if(a1[a]=='/') { b.chu2(c2); } } else if(c3==2&&c4==2)//无负数,无余数 { if(a1[a]=='+') { b.add(c2); } else if(a1[a]=='-') { b.jian1(c2); } else if(a1[a]=='*') { b.chen(c2); } else if(a1[a]=='/') { b.chu2(c2); } } else if(c3==2&&c4==1)//无负数,有余数 { if(a1[a]=='+') { b.add(c2); } else if(a1[a]=='-') { b.jian1(c2); } else if(a1[a]=='*') { b.chen(c2); } else if(a1[a]=='/') { b.chu1(c2); } } } else if(c1==2)//无乘除法 { if(c3==1) { b.jian2(c2); } else if(c3==2) { b.jian1(c2); } } } } else if(c==2) { System.out.println("请选择出题数量:"); Scanner input6=new Scanner(System.in); int c5=input6.nextInt(); System.out.println("请输入数值范围(最大值)"); Scanner input3=new Scanner(System.in); int c2=input3.nextInt(); System.out.println("请选择:1:有乘除法2:无乘除法"); Scanner input2=new Scanner(System.in); int c1=input2.nextInt(); for(int m=0;m<c5;m++) { if(c1==1)//有乘除法 { char[] a1={'+','-','*','/'}; int e1=(int)(Math.random()*4); int e2=(int)(Math.random()*4); int e3=(int)(Math.random()*4); char n1=a1[e1]; char n2=a1[e2]; char n3=a1[e3]; int x1=b.getrandom(c2); int x2=b.getrandom(c2); int x3=b.getrandom(c2); int x4=b.getrandom(c2); System.out.print(x1); System.out.print(n1); System.out.print(x2); System.out.print(n2); System.out.print(x3); System.out.print(n3); System.out.print(x4); System.out.print("="); System.out.println(); } else if(c1==2)//无乘除法 { char[] a1={'+','-'}; int e1=(int)(Math.random()*4); int e2=(int)(Math.random()*4); int e3=(int)(Math.random()*4); char n1=a1[e1]; char n2=a1[e2]; char n3=a1[e3]; int x1=b.getrandom(c2); int x2=b.getrandom(c2); int x3=b.getrandom(c2); int x4=b.getrandom(c2); System.out.print(x1); System.out.print(n1); System.out.print(x2); System.out.print(n2); System.out.print(x3); System.out.print(n3); System.out.print(x4); System.out.print("="); System.out.println(); } } } } public void add(int range) { int answer=0; int x=getrandom(range); int y=getrandom(range); System.out.print(x); System.out.print('+'); System.out.print(y); System.out.print("="); System.out.println(); System.out.println("请输入答案:"); Scanner in2=new Scanner(System.in); int q=in2.nextInt(); answer= x+ y; System.out.println(answer); if(q==answer) { System.out.println("回答正确!"); } else System.out.println("回答错误!"); } public void jian1(int range)//无负数 { int answer=0; int x=getrandom(range); int y=getrandom(range); if( x> y) { System.out.print(x); System.out.print('-'); System.out.print(y); System.out.print("="); System.out.println(); System.out.println("请输入答案:"); Scanner in2=new Scanner(System.in); int q=in2.nextInt(); answer=x-y; if(q==answer) { System.out.println("回答正确!"); } else System.out.println("回答错误!"); } } public void jian2(int range)//有负数 { int answer=0; int x=getrandom(range); int y=getrandom(range); System.out.print(x); System.out.print('-'); System.out.print(y); System.out.print("="); System.out.println(); System.out.println("请输入答案:"); Scanner in2=new Scanner(System.in); int q=in2.nextInt(); answer= x- y; System.out.println(answer); if(q==answer) { System.out.println("回答正确!"); } else System.out.println("回答错误!"); } public void chu1(int range)//有余数 { int answer=0; int x=getrandom(range); int y=getrandom(range); if(x%y!=0) { System.out.print(x); System.out.print('/'); System.out.print(y); System.out.print("="); System.out.println(); System.out.println("请输入答案:"); Scanner in2=new Scanner(System.in); int q=in2.nextInt(); int gcd=gcd(x,y); answer= (x/gcd)/(y/gcd); System.out.println(answer); if(q==answer) { System.out.println("回答正确!"); } else System.out.println("回答错误!"); } } public void chu2(int range)//无余数 { int answer=0; int x=getrandom(range); int y=getrandom(range); if(x%y==0) { System.out.print(x); System.out.print('/'); System.out.print(y); System.out.print("="); System.out.println(); System.out.println("请输入答案:"); Scanner in2=new Scanner(System.in); int q=in2.nextInt(); int gcd=gcd(x,y); answer= (x/gcd)/(y/gcd); System.out.println(answer); if(q==answer) { System.out.println("回答正确!"); } else System.out.println("回答错误!"); } } public void chen(int range) { int answer=0; int x=getrandom(range); int y=getrandom(range); System.out.print(x); System.out.print('*'); System.out.print(y); System.out.print("="); System.out.println(); System.out.println("请输入答案:"); Scanner in2=new Scanner(System.in); int q=in2.nextInt(); answer= x*y; System.out.println(answer); if(q==answer) { System.out.println("回答正确!"); } else System.out.println("回答错误!"); } public int getrandom(int c2) { int x=(int) ( Math.random() * c2 ); return x; } public int gcd(int x,int y) { int smaller=y>x?y:x; int i1=1; for(int i=1;i<smaller;i++) { if(y%i==0&&x%i==0) { i1=i; } } return i1; } }
设计思想:根据上周进度在进行改正,离理想目标还有很远。