加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Java > 正文

大二上学期 (2019-9-16 ) java课堂第一次随机测试和课上知识整

发布时间:2020-12-15 07:44:29 所属栏目:Java 来源:网络整理
导读:一、课堂测试 1、课堂测试:花二十分钟写一个能自动生成30道小学四则运算题目的 “软件” 要求 (1)减法结果不能为负数 ?? (2)乘法结果不得超过一百,除法结果必须为整数 ?? (3)题目避免重复; ?? (4)可定制(数量/打印方式); 2、程序设计思路 (1

一、课堂测试

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

要求 (1)减法结果不能为负数

?? (2)乘法结果不得超过一百,除法结果必须为整数

?? (3)题目避免重复;

?? (4)可定制(数量/打印方式);

2、程序设计思路

(1)产生两个1-100的随机数作为题目参与运算的数据,产生一个1-4的随机数作为加减乘除运算符打印

(2)用for循环控制出题个数c,用循环次数i对一行打印题目数求余为0达到一行出题要求输出换行

(3)在减法程序中用while(d1<d3)循环来保证减法结果不能为负数

(4)在乘法程序中用while(s1*s3>100)循环来保证乘法结果不超过一百,用循环判断除法最终结果为整数

(5)用一个二维数组和一个一维数组存储之前所有输入的数字和运算符,再用循环判断是不是重复生成,如果重复生成,则重新生成数字或者运算符,用来保证出题不重复。

 1 import java.util.Random;
 2 import java.util.Scanner;
 3 public class computer {
 4     public static Scanner input=new Scanner(System.in);
 5     public static int d1 = new Random().nextInt(100);
 6     public static int d2 = new Random().nextInt(100);
 7     public static int d3 = new Random().nextInt(100);
 8     public static int a[][]=new int[100000][2] ;
 9     public static int d[]=new int[100000];
10     public static void main(String[] args) {
11         int c;
12         int b;
13         System.out.println("请输入总题数:");
14          c=input.nextInt();
15         System.out.println("请输入每行的题数:");
16           b=input.nextInt();
17         for(int i=0;i<c;i++) {
18             if((i)%b==0)
19                 System.out.println();
20             System.out.print((i+1)+":");
21             d1 = new Random().nextInt(100);
22             System.out.print(d1);
23             d2 = new Random().nextInt(100);
24             d3 = new Random().nextInt(100);
25             a[i][0]=d1;//保存在二维数组中
26             a[i][1]=d3;
27             d[i]=d2;
28             
29             for(int j=0;j<i;j++) {
30                 if(a[j][0]==d1&&a[j][1]==d3&&d[j]==d2) {//查重
31                     d3 = new Random().nextInt(100);
32                     while(d3==a[i][1]) {
33                         d3 = new Random().nextInt(100);
34                 }
35                 d3 = new Random().nextInt(100);
36                 while(d3==a[i][1]) {
37                     
38                 }
39             }}
40             if(d2%4==0)
41                 System.out.print("+");
42             if(d2%4==1) {
43                 System.out.print("-");
44                 
45                     while(d1<d3) {
46                         d3 = new Random().nextInt(100);
47                     }
48                 
49             }
50                 
51             if(d2%4==2) {
52                 System.out.print("*");
53                 while(d1*d3>=100) {
54                     d3 = new Random().nextInt(100);
55                 }
56             }
57                 
58             if(d2%4==3) {
59                 System.out.print("/");
60                 while(d3!=0&&d1/d3!=0){
61                     d3 = new Random().nextInt(100);
62                 }
63             }
64             System.out.print(d3);
65             System.out.print("=");        
66             System.out.print("   ");
67         }  
68     } 
69 }

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读