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


    课堂测试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();
    			}	
    			}
    		
    		}
    	}
    

      

  • 相关阅读:
    常见的查找算法(七):哈希查找
    常见的查找算法(六):分块查找
    常见的查找算法(五):树表查找之一 ---- 二叉查找树
    让div充满整个body
    display:table的用法
    webpack-dev-server
    webpack--loader
    webpack nodejs npm关系
    js中==和===区别
    vue 的点击事件怎么获取当前点击的元素
  • 原文地址:https://www.cnblogs.com/xk1013/p/11568983.html
Copyright © 2020-2023  润新知