二柱子四则运算(课堂练习)

课堂测试1:像二柱子那样,花二十分钟写一个能自动生成30道小学四则运算题目的 “软件” 课堂测试2: (1)题目避免重复; (2)可定制(数量/打印方式)

package xk;
import java.util.Random;
import java.util.Scanner;
public class xk9 {
	public static int p[][]=new int[1000000][3];
	public static void main(String[] args) {
		System.out.println("请输入每一行的题目数:");
		Scanner sca=new Scanner(System.in);
		int n=sca.nextInt();
		System.out.println("请输入总题目数:");
		int m=sca.nextInt();
	  	String [] a =new String[4];
	  	a[0]="+";
	  	a[1]="-";
	  	a[2]="*";
	  	a[3]="/";
		Random rand = new Random();
		for(int i=0;i<m;i++) {
			int num1=rand.nextInt(100);
			Random c = new Random();
			int index = c.nextInt(4);
			int num2 = rand.nextInt(100); 
			p[i][0]=num1;
			p[i][1]=index;
			p[i][2]=num2;
			for(int j=0;j<i;j++) {
				if(p[j][0]==num1&&p[j][1]==index&&p[j][2]==num2) {
					num2 = new Random().nextInt(100);
					while(num2==p[i][2]) {
						num2 = new Random().nextInt(100);
					}
					num2 = new Random().nextInt(100);
					while(num2==p[i][2]) {}
				}
			}
			if(index==0) {
				System.out.print(i+1+". ");
				System.out.print(num1);
				 System.out.print(a[index]);
				 System.out.print(num2+"=     ");
			}
			if(index==1) {
				while(num1<num2) {
					num1=rand.nextInt(100);
					num2 = rand.nextInt(100);
				}
				System.out.print(i+1+". ");
				System.out.print(num1);
				 System.out.print(a[index]);
				 System.out.print(num2+"=     ");	
			}
			if(index==2) {
				while(num1*num2>=100) {
				num1=rand.nextInt(100);
				num2 = rand.nextInt(100);
				}
				System.out.print(i+1+". ");
				System.out.print(num1);
				 System.out.print(a[index]);
				 System.out.print(num2+"=     ");
			}
			if(index==3) {
				while(num2==0||num1%num2!=0)
				{
					num2 = rand.nextInt(100);
				}
				System.out.print(i+1+". ");
				System.out.print(num1);
				 System.out.print(a[index]);
				 System.out.print(num2+"=     ");
			} 
			if((i+1)%n==0) {
				System.out.println();
			}	
			}
		
		}
	}

  

posted @ 2019-09-18 20:17  kai_kaikai  阅读(166)  评论(0编辑  收藏  举报