出30道四则运算题目

第一阶段

课堂测试1:像二柱子那样,花二十分钟写一个能自动生成30道小学四则运算题目的 “软件”

import java.util.Random;

public class sizeyunxuan {

    
    
    public static void main(String[] args) {
        int a;
        for(a=0;a<8;a++)
        {
            Random r= new Random();
            int i=r.nextInt(10);
            int j=r.nextInt(10);
             System.out.println(i+"+"+j+"=");
             System.out.println(i+"-"+j+"=");
             System.out.println(i+"*"+j+"=");
             System.out.println(i+"/"+j+"=");
        }

    }

}

 

课堂测试2: (1)题目避免重复; (2)可定制(数量/打印方式);

package pk1;
import java.util.Random;

import java.util.Scanner;


public class sizeyunxuan {
    
    public static void operate() {
        String[]operate=new String[]{"+","-","*","/"};
        Random r=new Random();
         System.out.print(operate[r.nextInt(4)]);
    }
    
    //public class shuju {
        
    //    Random r=new Random();
     //int i=r.nextInt(100);
        //int j=r.nextInt(100);
    
    //}
        
        
    public static void main(String[] args) {
        
    int []a=new int[100];
    int []b=new int[100];
    
    
    Scanner scan =new Scanner(System.in);
    int n;
    System.out.println("请输入需要的题目数:");
    n=scan.nextInt();
    
        
        
        int i,j;
        for(i=0;i<n;i++)
        {

            Random r=new Random();
            a[i]=r.nextInt(99);
            b[i]=r.nextInt(99);
        
            for(j=0;j<i;j++) {
            if(a[i]==b[j]&&b[i]==a[j]) {
                a[i]=r.nextInt(99)-1;
            }
            }
            int t=(int)r.nextInt(4);
            switch(t)
            {
            case 0:
                 System.out.println(a[i]+" + "+b[i]+"=");
                 break;
            case 1:
                 System.out.println(a[i]+" - "+b[i]+"=");
                 break;
            case 2:
                 System.out.println(a[i]+" * "+b[i]+"=");
                 break;
            case 3:
                 System.out.println(a[i]+" / "+b[i]+"=");
                 break;
            }
        
            
             
            
        }

    }

}

 

上一篇:0911京东笔试


下一篇:计应193张跃 四则运算系统