题目:

一家软件公司程序员二柱的小孩上了小学二年级,老师让家长每天出30道四则运算题目给小学生做。

二柱一下打印出好多份不同的题目,让孩子做了。老师看了作业之后,对二柱赞许有加。别的老师闻讯, 问二柱能否扩大他的影响力,编个软件,给二年级到四年级都用,多了一些小小的要求:

1、题目避免重复(第二阶段)

2、可定制(数量/打印方式):输入大的数量值,测试一下系统是否崩溃,反向查找系统是否优化的余地

3、定制操作数的个数

4、定制是否有乘除法

5、定制是否有括号(随机加入)

6 、定制数值范围(确定操作数的取值范围)

建立了s包,建立了number类,创建了主函数main();,以及三个函数o1();o2();o3();

package s;

import java.util.Random;
import java.util.Scanner;
import java.util.*;

public class number {
public static void main(String[] args)
{
boolean flag = true;
while(flag) {
System.out.println("请选择功能(1、2、3):");
Scanner sc = new Scanner(System.in);
int z = sc.nextInt();
switch(z) {
case 1:
o1();break;
case 2:
o2();break;
case 3:
o3();break;
default:System.out.println("没有此功能。");break;
}
}
}

public static void o1()//第一阶段
{
Random random = new Random();

Scanner sc = new Scanner(System.in);
System.out.println("请输入打印的题数:");
int m = sc.nextInt();

for(int o = 1; o <= m; o++) {
int a = random.nextInt(4);
int b = random.nextInt(100);
int c = random.nextInt(100);
switch(a)
{
case 0:

System.out.println(b+ "+" +c +"=" );
break;
case 1:

System.out.println(b+ "-" +c +"=" );
break;
case 2:

System.out.println(b+ "*" +c +"=" );
break;
case 3:

System.out.println(b+ "/" +c +"=" );
break;

default:
break;
}
}

}

public static void o2()//第二阶段
{
Random random = new Random();

Scanner sc = new Scanner(System.in);
System.out.println("请输入打印的题数:");
int m = sc.nextInt();

StringBuffer str = new StringBuffer();
String[] s = new String[m];
s[0] = str.toString();

for(int o = 0; o < m; o++) {

int a = random.nextInt(4);
int b = random.nextInt(100);
int c = random.nextInt(100);

str.append(a).append(b).append(c);
StringBuffer str2 = new StringBuffer();
s[o] = str2.append(a).append(b).append(c).toString();

int sum = 0;
for(int q = 0; q < s.length; q++) {
if(s[o].equals(s[q])) {
sum++;
}
}

if(sum == 1)
{
if(a == 0) {

System.out.println(b + "+" + c + "=");
}
if(a == 1) {

System.out.println(b + "-" + c + "=");
}
if(a == 2) {

System.out.println(b + "*" + c + "=");
}
if(a == 3) {

System.out.println(b + "/" + c + "=");
}

}else if(sum != 1){
o--;
continue;

}
}
}

public static void o3()//第三阶段
{
Scanner sc = new Scanner(System.in);
System.out.println("请输入打印的题数:");
int g = sc.nextInt();

System.out.println("有无乘除法,请输入y或n:");
String g1 = sc.next();

System.out.println("是否有括号,请输入y或n:");
String g2 = sc.next();

System.out.println("请输入操作个数(2-4):");
int g3 = sc.nextInt();

System.out.println("请输入操作数范围【50-200】:");
int g4 = sc.nextInt();

Random random = new Random();
int a = random.nextInt(4);
int a0 = random.nextInt(g3)+2;//操作数个数(2-4)

StringBuffer str = new StringBuffer();//动态数组
String[] s = new String[g];
s[0] = str.toString();//返回对象值

for( int i = 0; i < g; i++) {
a = random.nextInt(4);
int a1 = random.nextInt(g4);
int a2 = random.nextInt(g4);
int a3 = random.nextInt(g4);
int a4 = random.nextInt(g4);

if(g4 >=50 && g4 <=200){
a1 = random.nextInt(g4);
a2 = random.nextInt(g4);
a3 = random.nextInt(g4);
a4 = random.nextInt(g4);
}else {
System.out.println("操作数超出范围。");
}

if(g3 == 2) {
str.append(a).append(a1).append(a2);//添加数据
}else if(g3 ==3) {
str.append(a).append(a1).append(a2).append(a3);//添加数据
}else {
str.append(a).append(a1).append(a2).append(a3).append(a4);//添加数据
}

StringBuffer str2 = new StringBuffer();
if(g3 == 2) {
s[i] = str2.append(a).append(a1).append(a2).toString();
}else if(g3 == 3){
s[i] = str2.append(a).append(a1).append(a2).append(a3).toString();
}else {
s[i] = str2.append(a).append(a1).append(a2).append(a3).append(a4).toString();
}

int sum = 0;
for(int q = 0; q < s.length; q++)
{if(s[i].equals(s[q])) {sum++;}}

if(g3 == 2) {
if(g1.equals("n")) {
if(sum == 1)
{
if(a == 0) {System.out.println(a1 + "+" + a2 + "=");}
if(a == 1) {System.out.println(a1 + "-" + a2 + "=");}
if(a == 2) {i--;continue;}
if(a == 3) {i--;continue;}
}else if(sum != 1){i--;continue;}
}else if(g1.equals("y")) {
if(sum == 1)
{
if(a == 0) {System.out.println(a1 + "+" + a2 + "=");}
if(a == 1) {System.out.println(a1 + "-" + a2 + "=");}
if(a == 2) {System.out.println(a1 + "*" + a2 + "=");}
if(a == 3) {System.out.println(a1 + "/" + a2 + "=");}
}else if(sum != 1){i--;continue;}
}
}else if(g3 == 3) {
if(g1.equals("n")) {
if(sum == 1)
{
if(a == 0) {System.out.println(a1 + "-" +"("+ a2 +"+"+a3+")"+ "=");}
if(a == 1) {System.out.println("("+a1 + "-" + a2 +")"+"+"+a3+ "=");}
if(a == 2) {System.out.println("("+a1 + "+" + a2 +")"+"-"+a3+ "=");}
if(a == 3) {System.out.println(a1 + "+" +"("+ a2 +"-"+a3+")"+ "=");}
}else if(sum != 1){i--;continue;}
}else if(g1.equals("y")) {
if(sum == 1)
{
if(a == 0) {System.out.println("("+a1+"*" + a2+")"+"+" + a3 +"=");}
if(a == 1) {System.out.println(a1+"-" +"("+ a2+"/" + a3 +")"+"=");}
if(a == 2) {System.out.println(a1+"-" +"("+ a2+"*" + a3 +")"+"=");}
if(a == 3) {System.out.println("("+a1+"/" + a2+")"+"+" + a3 +"=");}
}else if(sum != 1){i--;continue;}
}
}else if(g3 == 4){
if(g1.equals("n")) {
if(sum == 1)
{
if(a == 0) {System.out.println(a1+"+" + "("+ a2+"+" +a3 +")"+"+" +a4+ "=");}
if(a == 1) {System.out.println(a1+"-" + "("+ a2+"+" +a3 +")"+"-" +a4+ "=");}
if(a == 2) {System.out.println(a1+"-" + a2+"-" + "("+a3 +"-" +a4+")"+ "=");}
if(a == 3) {System.out.println("("+a1+"+" + a2+")"+"-" + a3 +"+" +a4+ "=");}
}else if(sum != 1){i--;continue;}
}else if(g1.equals("y")) {
if(sum == 1)
{
if(a == 0) {System.out.println(a1+"+" + a2+"-" + "("+a3 +"*" +a4+")"+ "=");}
if(a == 1) {System.out.println(a1+"-" +"("+ a2+"/" + a3 +")"+"-" +a4+ "=");}
if(a == 2) {System.out.println("("+a1+"*" + a2+")"+"+" + a3 +"-" +a4+ "=");}
if(a == 3) {System.out.println("("+a1+"/" + a2+")"+"-" +"("+ a3 +"*" +a4+")"+ "=");}
}else if(sum != 1){i--;continue;}
}
}else {
System.out.println("操作个数超出范围。");
}
}

}
}

日常Java(测试 (二柱)修改版)2021/9/22的更多相关文章

  1. 日常Java测试 2021/11/14

    课堂测试三 package word_show; import java.io.*;import java.util.*;import java.util.Map.Entry; public clas ...

  2. 日常Java测试第一段 2021/11/12

    课堂测试一 package word_show;import java.io.BufferedReader;import java.io.FileNotFoundException;import ja ...

  3. 日常Java测试第二段 2021/11/12

    第二阶段 package word_show; import java.io.*;import java.util.*;import java.util.Map.Entry; public class ...

  4. ORM框架示例及查询测试,上首页修改版(11种框架)

    继上次ORM之殇,我们需要什么样的ORM框架? 整理了11个ORM框架测试示例,通过示例代码和结果,能很容易了解各种框架的特性,优缺点,排名不分先后 EF PDF XCODE CRL NHiberna ...

  5. 转载:Eclipse+Spket插件+ExtJs4修改版提供代码提示功能[图]

    转载:Eclipse+Spket插件+ExtJs4修改版提供代码提示功能[图] ExtJs是一种主要用于创建前端用户界面,是一个基本与后台技术无关的前端ajax框架.功能丰富,无人能出其右.无论是界面 ...

  6. Indy 10.5.8 for Delphi and Lazarus 修改版(2011)

    Indy 10.5.8 for Delphi and Lazarus 修改版(2011)    Internet Direct(Indy)是一组开放源代码的Internet组件,涵盖了几乎所有流行的I ...

  7. Java进阶(二十五)Java连接mysql数据库(底层实现)

    Java进阶(二十五)Java连接mysql数据库(底层实现) 前言 很长时间没有系统的使用java做项目了.现在需要使用java完成一个实验,其中涉及到java连接数据库.让自己来写,记忆中已无从搜 ...

  8. 20175212童皓桢 Java实验二-面向对象程序设计实验报告

    20175212童皓桢 Java实验二-面向对象程序设计实验报告 实验内容 初步掌握单元测试和TDD 理解并掌握面向对象三要素:封装.继承.多态 初步掌握UML建模 熟悉S.O.L.I.D原则 了解设 ...

  9. 若快打码平台python开发文档修改版

    一.打码的作用 在进行爬虫过程中,部分网站的登录验证码是比较简单的,例如四个英文数字随机组合而成的验证码,有的是全数字随机组成的验证码,有的是全中文随机组成的验证码.为了爬虫进行自动化,需要解决自动登 ...

随机推荐

  1. 验证人员应该以何种角度阅读spec

    转载:验证人员应该以何种角度阅读spec - 微波EDA网 (mweda.com) 在开发流程中,设计和验证人员关注的点肯定是不一样的,尤其在spec的理解上,验证人员往往需要有自己独立的理解.在拿到 ...

  2. populating-next-right-pointers-in-each-node leetcode C++

    Given a binary tree struct TreeLinkNode { TreeLinkNode *left; TreeLinkNode *right; TreeLinkNode *nex ...

  3. js和jq文档操作

    JS文档操作 一.dom树结构 1.元素节点 2.文本节点 3.属性节点      不属于元素节点的子节点  4.文档节点(document) 二.处理元素节点    method    1.docu ...

  4. (二)FastDFS 高可用集群架构学习---搭建

    一.单group 单磁盘 的 FastDFS 集群 a.前期准备 1.系统软件说明: 名称 说明 CentOS 7.x(安装系统) libfastcommon FastDFS分离出的一些公用函数包 F ...

  5. [源码解析] PyTorch 分布式(2) ----- DataParallel(上)

    [源码解析] PyTorch 分布式(2) ----- DataParallel(上) 目录 [源码解析] PyTorch 分布式(2) ----- DataParallel(上) 0x00 摘要 0 ...

  6. springcloud zuul shiro网关鉴权并向服务传递用户信息

    1.pom文件 <dependencies> <!--eureka客户端--> <dependency> <groupId>org.springfram ...

  7. 难顶!面试官问我G1垃圾收集器

    面试官:要不这次来聊聊G1垃圾收集器? 候选者:嗯嗯,好的呀 候选者:上次我记得说过,CMS垃圾收集器的弊端:会产生内存碎片&&空间需要预留 候选者:这俩个问题在处理的时候,很有可能会 ...

  8. 【SVG】SVG的夺命利器——path

    [SVG]SVG的夺命利器--path 博客说明 文章所涉及的资料来自互联网整理和个人总结,意在于个人学习和经验汇总,如有什么地方侵权,请联系本人删除,谢谢! 说明 昨天一发布,突然看到有朋友留言,希 ...

  9. Part 38 AngularJS cancel route change

    n this video we will discuss, how to cancel route change in Angular with an example. This is extreme ...

  10. 暑假算法练习Day2

    第二天啦!大家一起冲冲冲!! 1004 成绩排名 (20 分) 读入 n(>0)名学生的姓名.学号.成绩,分别输出成绩最高和成绩最低学生的姓名和学号. 输入格式: 每个测试输入包含 1 个测试用 ...