首页 > 其他分享 >四则运算测试二

四则运算测试二

时间:2022-09-30 17:15:10浏览次数:38  
标签:int 四则运算 System nextInt 测试 print mult out

package operation;
import java.util.Random;
import java.util.Scanner;
public class operation {
public static int number = 0;//个数
public static int mult = 0;//操作数的个数
public static int bracket = 0;//操作符个数,最多不过五
public static int num = 0;//括号
public static int count = 0;//换行数
public static int max = 0;//范围
public static int division;//乘除
public static void main(String[] args) {
menu();
Random r = new Random();
int s = mudi(division);
int a;
int[] arr1 = new int[number * mult];//所有的数字
int[] arr2 = new int[number];
String[] arr3 = new String[number * (mult - 1)];//符号
String[] arr4 = new String[number];
int sum = 0;


//mult-1
if (bracket == 1) {
int symbol1 = 0;
int symbol2 = 0;
for (int i = 0; i < number; i++) {//for循环输出所有个数
count++;
symbol1 = r.nextInt(3);
symbol2 = r.nextInt(2);

if (symbol1 == 0) {
for (int j = 0; j < mult; j++) {//for循环输出公式,输出没有括号的公式
if (j == mult - 1) {
a = r.nextInt(max);
System.out.print(a + "=\t");
arr2[j] = a;
} else {
a = r.nextInt(max);
System.out.print(a);
arr4[j] = fuHao(s);
arr2[j] = a;
}
}
}else if (symbol1 == 1) {
for (int j = 0; j < mult; j++) {
if (j == mult - 1) {
a = r.nextInt(max);
System.out.print(a);
if (symbol2 == 1 && j == mult - 1) {
System.out.print(")");
}
System.out.print("=\t");
arr2[j] = a;
} else {
a = r.nextInt(max);
if(j == 0){
System.out.print("(");}
System.out.print(a);
if (symbol2 == 0 && j == mult - 2) {
System.out.print(")");
}
arr2[j] = a;
arr4[j] = fuHao(s);
}
}
}else if (symbol1 == 2) {
for (int j = 0; j < mult; j++) {
if (j == mult - 1) {
a = r.nextInt(max);
System.out.print(a);
if (symbol2 == 1 && j == mult - 1) {
System.out.print(")");
}
System.out.print("=\t");
arr2[j] = a;
} else {
a = r.nextInt(max);
if(j == 1)
{System.out.print("(");}
System.out.print(a);
if (symbol2 == 0 && j == mult - 3) {
System.out.print(")");
}
arr2[j] = a;
arr4[j] = fuHao(s);
}
}
}
for (int x = 0; x < number; x++) {
arr1[x + sum] = arr2[x];
arr3[x + sum] = arr4[x];
sum++;
}
if (count % num == 0)
System.out.println();
}
} else if (bracket == 0) {
for (int i = 0; i < number; i++) {//for循环输出所有个数
count++;
for (int j = 0; j < mult; j++) {//for循环输出公式

if (j == mult - 1) {
a = a = r.nextInt(max);
System.out.print(a + "=\t");
} else {
a = r.nextInt(max);
System.out.print(a);
fuHao(s);
}
}
if (count % num == 0)
System.out.println();
}
}
System.out.println("重复率为0");
//做题
//arr1[] 是所有的数字
//arr1[]/mult是number
//arr3[] 符号

int[] answer = new int[number];
for (int q = 0; q < number; q = q+mult) {//实现答案的输出

int shu = 0;
//arr1[0] arr3[0] arr1[1] arr3[1] arr1[2] arr3[2] arr1[3] = answer[0];
for (int i = 0; i < mult; i++) {
if (arr3[i + shu] == "+") answer[i] = arr1[i] + answer[i];
if (arr3[i + shu] == "-") answer[i] = arr1[i] - answer[i];
if (arr3[i + shu] == "*") answer[i] = arr1[i] * answer[i];
if (arr3[i + shu] == "/") answer[i] = arr1[i] / answer[i];
}

shu++;
}




























}







private static int mudi(int division) {
int s = 0;
if(division == 0){//调整是否有乘除法
division = 2;
}else if(division == 1)
{
division=4;
}
s = division;
return s;
}


//System.out.print(arr2[i] + "=\t");
private static void menu() { //菜单

Scanner sc = new Scanner(System.in);
System.out.println("请输入你要生成题目的个数:");
number = sc.nextInt();//个数
System.out.println("请输入每行的题数:");
num = sc.nextInt();//每行题目的个数
System.out.println("请输入操作数的个数:");
mult = sc.nextInt();//操作符个数
System.out.println("请输入是否有乘法除法,0是没有,1是有:");
division = sc.nextInt();
System.out.println("请选择是否有括号,0是没有,1是有:");
bracket = sc.nextInt();//括号
System.out.println("请输入出题数值的范围:");
max = sc.nextInt();//范围
}

public static String fuHao(int division) { //调用符号
Random r = new Random();
int a=r.nextInt(division)+1;
String zz = "";
if(a==1) {System.out.print("+");
zz = "+";}
if(a==2) {System.out.print("-");
zz = "-";}
if(a==3) {System.out.print("*");
zz = "*";}
if(a==4) {System.out.print("/");
zz = "/";}
return zz;
}
}

 

 

 

 

 

标签:int,四则运算,System,nextInt,测试,print,mult,out
From: https://www.cnblogs.com/yzx-sir/p/16745504.html

相关文章

  • postman 模拟form Post 测试传入List<String>参数方式
    1.postman测试传入List<String>参数方式  http://www.zzvips.com/article/206812.html 2.关于postman的form-data如何传递数组形式 https://blog.csdn.net/chrispaul......
  • 2022 年十大接口测试工具合集
    接口测试的全称是应用程序编程接口(API)测试,从原理上来说,接口测试是模拟客户端向服务器端发送请求,然后检查能否获得正确的返回信息。接口测试用于测试RESTfulAPI、SOAPWeb......
  • 亚马逊攀岩安全带ASTM F1772安全规范测试报告
    亚马逊要求所有发布出售的攀岩绳必须经过检测。必须符合下面列出的特定法规或标准要求:产品名称:ZLR13Ee(威同号)法规或标准要求攀岩绳:EN892:2012+A1:2016(登山装备、动力登山......
  • 谷歌测试定律
    来源:https://slxiao.github.io/ 什么是谷歌测试定律?软件测试(SoftwareTesting)是软件工程(SoftwareEngineering)中不可或缺的一个过程。软件测试触发预定义的测试步......
  • 高颜值测试报告- XTestRunner
     基于unittest框架现代风格测试报告。特点漂亮测试报告让你更愿意编写测试。支持单元、WebUI、API 各种类型的测试。支持Selenium运行失败/错误自动截图。支持......
  • 使用福禄克CFP光纤测试仪进行Tier 1和Tier 2光纤测试
    与可通过光损耗测试仪(OLTs)实现的衰减(插入损耗)、长度和极性所需的第1层测试不同,该领域的技术人员很少会面临第2层测试和光时域反射计(OTDR)的需要。但偶尔会有一位客户或顾问指......
  • 福禄克DSX2-5000ch网线认证测试仪为您规避布线错误
    虽然安装、测试和认证网络布线设备的聪明人知道满足标准性能参数和确保应用程序支持的重要性,但即使是我们中最优秀的人也可能犯错误,对底线和客户满意度产生不利影响。让我们......
  • AM5728 Preempt-RT Igh Ethercat安装与测试IgH EtherCAT Master 源码编译安装
    各大平台的测试数据:KPAEtherCAT主站在Zynq平台的移植与测试 ......
  • 测试架构师必备技能-Nginx安装部署实战
    每天进步一点点,关注我们哦,每天分享测试技术文章本文章出自【码同学软件测试】码同学公众号:自动化软件测试,领取资料可加:magetest码同学抖音号:小码哥聊软件测试Nginx("en......
  • QA如何写测试方案
    写在前面:当QA成为大型项目的QAowner时,那么测试方案就成为QA整个项目流程中的重要的工作指南。那测试方案中,要写些什么内容呢?希望这篇文章可以提供给你很好的思路;ps: 每个......