博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
件工程个人作业02
阅读量:6676 次
发布时间:2019-06-25

本文共 9821 字,大约阅读时间需要 32 分钟。

1.源代码:package dijia;

import java.util.Scanner;
import java.util.Random;
public class text2 {

public static void chengchu()

{
System.out.println("整数运算请输入1;分数预算请输入2");

Random random = new Random();

Scanner scanner = new Scanner(System.in);
int bb = scanner.nextInt();
if(bb == 1)
{
System.out.println("请输入题目的个数:");
int M = scanner.nextInt();
//定义变量
int m=0;
//创建M个数组储存M道题
int [][] a = new int[M][4];
//产生30道题目
for(int i = 0;i < M;i++)
{
a[i][0] = random.nextInt(100);
a[i][2] = random.nextInt(100);
a[i][1] = random.nextInt(4);
}
//排除重复的题目
while(m <= (M - 1)*M/2)
{
for(int j = 0;j < M;j++)
{
for(int k = j+1;k < M;k++)
{
m++;
if((a[j][0] == a[k][0] && a[j][1] == a[k][1] && a[j][2] == a[k][2]) || (a[j][1] == 3 && a[j][2] == 0))
{
int b = (int)Math.random()*100;
int c = (int)Math.random()*100;
int d = (int)Math.random()*4;
a[k][0] = b;
a[k][1] = d;
a[k][2] = c;
}
}
}
}
//输出题目
for(int i = 0;i < M;i++)
{
if(a[i][1] == 2)
{
System.out.println(a[i][0]+"*"+a[i][2]+"=");
}
if(a[i][1] == 3)
{
System.out.println(a[i][0]+"/"+a[i][2]+"=");
}
}
}
//分数运算
if(bb == 2)
{
System.out.println("请输入题目的个数:");
int MM = scanner.nextInt();
int nn = 0;
//定义相关数组
int a1[] = new int [MM];//储存第一个分数的分子
int b1[] = new int [MM];//储存第二个分数的分子
int a2[] = new int [MM];//储存第一个分数的分母
int b2[] = new int [MM];//储存第二个分数的分母
int cc[] = new int [MM];//储存四则运算符号
char dd[] ={'*','/'};
for(int i = 0;i < MM;i++)
{
a1[i] = random.nextInt(100);
a2[i] = random.nextInt(100);
b1[i] = random.nextInt(100);
b2[i] = random.nextInt(100);
cc[i] = random.nextInt(2);
}
//排除的分数题目
while(nn <= MM*(MM-1)/2)
{
for(int iii = 0;iii < MM;iii++)
{
nn++;
for(int ii = iii+1;ii < MM;ii++)
{
nn++;
if( (cc[ii] == 3 && b1[ii] == 0) || b2[ii] == 0 || a2[ii] == 0 || (a1[ii] >= a2[ii]) || (b1[ii] >= b2[ii]) || (a1[ii] == a1[iii] && b1[ii] == b1[iii] && a2[ii] == a2[iii] && b2[ii] == b2[iii] && cc[ii] == cc[iii]))
{
a1[ii] = random.nextInt(100);
a2[ii] = random.nextInt(100);
b1[ii] = random.nextInt(100);
b2[ii] = random.nextInt(100);
cc[ii] = random.nextInt(2);
}
}
}
}
//输出题目
for(int jj = 0;jj < MM;jj++)
{
System.out.println("("+a1[jj]+"/"+a2[jj]+")"+dd[cc[jj]]+"("+b1[jj]+"/"+b2[jj]+")"+"=");
}

}

}
public static void jiajian()
{
System.out.println("整数运算请输入1;分数预算请输入2");

Random random = new Random();

Scanner scanner = new Scanner(System.in);
int bb = scanner.nextInt();
if(bb == 1)
{
System.out.println("请输入题目的个数:");
int M = scanner.nextInt();
//定义变量
int m=0;
//创建M个数组储存M道题
int [][] a = new int[M][4];
//产生30道题目
for(int i = 0;i < M;i++)
{
a[i][0] = random.nextInt(100);
a[i][2] = random.nextInt(100);
a[i][1] = random.nextInt(4);
}
//排除重复的题目
while(m <= (M - 1)*M/2)
{
for(int j = 0;j < M;j++)
{
for(int k = j+1;k < M;k++)
{
m++;
if((a[j][0] == a[k][0] && a[j][1] == a[k][1] && a[j][2] == a[k][2]) || (a[j][1] == 3 && a[j][2] == 0))
{
int b = (int)Math.random()*100;
int c = (int)Math.random()*100;
int d = (int)Math.random()*4;
a[k][0] = b;
a[k][1] = d;
a[k][2] = c;
}
}
}
}
//输出题目
for(int i = 0;i < M;i++)
{
if(a[i][1] == 0)
{
System.out.println(a[i][0]+"+"+a[i][2]+"=");
}
if(a[i][1] == 1)
{
System.out.println(a[i][0]+"-"+a[i][2]+"=");
}
}
}
//分数运算
if(bb == 2)
{
System.out.println("请输入题目的个数:");
int MM = scanner.nextInt();
int nn = 0;
//定义相关数组
int a1[] = new int [MM];//储存第一个分数的分子
int b1[] = new int [MM];//储存第二个分数的分子
int a2[] = new int [MM];//储存第一个分数的分母
int b2[] = new int [MM];//储存第二个分数的分母
int cc[] = new int [MM];//储存四则运算符号
char dd[] ={'+','-','*','/'};
for(int i = 0;i < MM;i++)
{
a1[i] = random.nextInt(100);
a2[i] = random.nextInt(100);
b1[i] = random.nextInt(100);
b2[i] = random.nextInt(100);
cc[i] = random.nextInt(2);
}
//排除的分数题目
while(nn <= MM*(MM-1)/2)
{
for(int iii = 0;iii < MM;iii++)
{
nn++;
for(int ii = iii+1;ii < MM;ii++)
{
nn++;
if( (cc[ii] == 3 && b1[ii] == 0) || b2[ii] == 0 || a2[ii] == 0 || (a1[ii] >= a2[ii]) || (b1[ii] >= b2[ii]) || (a1[ii] == a1[iii] && b1[ii] == b1[iii] && a2[ii] == a2[iii] && b2[ii] == b2[iii] && cc[ii] == cc[iii]))
{
a1[ii] = random.nextInt(100);
a2[ii] = random.nextInt(100);
b1[ii] = random.nextInt(100);
b2[ii] = random.nextInt(100);
cc[ii] = random.nextInt(2);
}
}
}
}
//输出题目
for(int jj = 0;jj < MM;jj++)
{
System.out.println("("+a1[jj]+"/"+a2[jj]+")"+dd[cc[jj]]+"("+b1[jj]+"/"+b2[jj]+")"+"=");
}

}

}
public static void kuohao()
{
Random random = new Random();
Scanner scanner = new Scanner(System.in);
System.out.println("请输入题目的个数:");
int N = scanner.nextInt();
char e []= {'+','-'};
char f []= {'+','-'};
for(int i = 0;i < N;i++)
{
int a,b,c,d;
a = random.nextInt(100);
b = random.nextInt(100);
c = random.nextInt(100);
d = random.nextInt(2);
System.out.println("("+a+e[d]+b+")"+f[d]+c+"=");
}
}
public static void fanwei()
{
System.out.println("请数入范围的最小值");
Random random = new Random();
Scanner scanner = new Scanner(System.in);
int aa = scanner.nextInt();
System.out.println("请数入范围的最大值");
int bb = scanner.nextInt();
System.out.println("整数运算请输入1;分数预算请输入2");

int bbb = scanner.nextInt();
if(bb == 1)
{
System.out.println("请输入题目的个数:");
int M = scanner.nextInt();
//定义变量
int m=0;
//创建M个数组储存M道题
int [][] a = new int[M][4];
//产生30道题目
for(int i = 0;i < M;i++)
{
a[i][0] = random.nextInt(bbb-aa)+aa;
a[i][2] = random.nextInt(bbb-aa)+aa;
a[i][1] = random.nextInt(4);
}
//排除重复的题目
while(m <= (M - 1)*M/2)
{
for(int j = 0;j < M;j++)
{
for(int k = j+1;k < M;k++)
{
m++;
if((a[j][0] == a[k][0] && a[j][1] == a[k][1] && a[j][2] == a[k][2]) || (a[j][1] == 3 && a[j][2] == 0))
{
int b = (int)Math.random()*bbb+aa;
int c = (int)Math.random()*bbb+aa;
int d = (int)Math.random()*4;
a[k][0] = b;
a[k][1] = d;
a[k][2] = c;
}
}
}
}
//输出题目
for(int i = 0;i < M;i++)
{
if(a[i][1] == 0)
{
System.out.println(a[i][0]+"+"+a[i][2]+"=");
}
if(a[i][1] == 1)
{
System.out.println(a[i][0]+"-"+a[i][2]+"=");
}
if(a[i][1] == 2)
{
System.out.println(a[i][0]+"*"+a[i][2]+"=");
}
if(a[i][1] == 3)
{
System.out.println(a[i][0]+"/"+a[i][2]+"=");
}
}
}
//分数运算
if(bb == 2)
{
System.out.println("请输入题目的个数:");
int MM = scanner.nextInt();
int nn = 0;
//定义相关数组
int a1[] = new int [MM];//储存第一个分数的分子
int b1[] = new int [MM];//储存第二个分数的分子
int a2[] = new int [MM];//储存第一个分数的分母
int b2[] = new int [MM];//储存第二个分数的分母
int cc[] = new int [MM];//储存四则运算符号
char dd[] ={'+','-','*','/'};
for(int i = 0;i < MM;i++)
{
a1[i] = random.nextInt(bbb-aa)+aa;
a2[i] = random.nextInt(bbb-aa)+aa;
b1[i] = random.nextInt(bbb-aa)+aa;
b2[i] = random.nextInt(bbb-aa)+aa;
cc[i] = random.nextInt(4);
}
//排除的分数题目
while(nn <= MM*(MM-1)/2)
{
for(int iii = 0;iii < MM;iii++)
{
nn++;
for(int ii = iii+1;ii < MM;ii++)
{
nn++;
if( (cc[ii] == 3 && b1[ii] == 0) || b2[ii] == 0 || a2[ii] == 0 || (a1[ii] >= a2[ii]) || (b1[ii] >= b2[ii]) || (a1[ii] == a1[iii] && b1[ii] == b1[iii] && a2[ii] == a2[iii] && b2[ii] == b2[iii] && cc[ii] == cc[iii]))
{
a1[ii] = random.nextInt(100);
a2[ii] = random.nextInt(100);
b1[ii] = random.nextInt(100);
b2[ii] = random.nextInt(100);
cc[ii] = random.nextInt(4);
}
}
}
}
//输出题目
for(int jj = 0;jj < MM;jj++)
{
System.out.println("("+a1[jj]+"/"+a2[jj]+")"+dd[cc[jj]]+"("+b1[jj]+"/"+b2[jj]+")"+"=");
}

}

}
public static void fushu()
{
System.out.println("整数运算请输入1;分数预算请输入2");

Random random = new Random();

Scanner scanner = new Scanner(System.in);
int bb = scanner.nextInt();
if(bb == 1)
{
System.out.println("请输入题目的个数:");
int M = scanner.nextInt();
//定义变量
int m=0;
//创建M个数组储存M道题
int [][] a = new int[M][4];
//产生30道题目
for(int i = 0;i < M;i++)
{
a[i][0] = random.nextInt(100)*(-1);
a[i][2] = random.nextInt(100);
a[i][1] = random.nextInt(4);
}
//排除重复的题目
while(m <= (M - 1)*M/2)
{
for(int j = 0;j < M;j++)
{
for(int k = j+1;k < M;k++)
{
m++;
if((a[j][0] == a[k][0] && a[j][1] == a[k][1] && a[j][2] == a[k][2]) || (a[j][1] == 3 && a[j][2] == 0))
{
int b = (int)Math.random()*100*(-1);
int c = (int)Math.random()*100;
int d = (int)Math.random()*4;
a[k][0] = b;
a[k][1] = d;
a[k][2] = c;
}
}
}
}
//输出题目
for(int i = 0;i < M;i++)
{
if(a[i][1] == 0)
{
System.out.println(a[i][0]+"+"+a[i][2]+"=");
}
if(a[i][1] == 1)
{
System.out.println(a[i][0]+"-"+a[i][2]+"=");
}
if(a[i][1] == 2)
{
System.out.println(a[i][0]+"*"+a[i][2]+"=");
}
if(a[i][1] == 3)
{
System.out.println(a[i][0]+"/"+a[i][2]+"=");
}
}
}
//分数运算
if(bb == 2)
{
System.out.println("请输入题目的个数:");
int MM = scanner.nextInt();
int nn = 0;
//定义相关数组
int a1[] = new int [MM];//储存第一个分数的分子
int b1[] = new int [MM];//储存第二个分数的分子
int a2[] = new int [MM];//储存第一个分数的分母
int b2[] = new int [MM];//储存第二个分数的分母
int cc[] = new int [MM];//储存四则运算符号
char dd[] ={'+','-','*','/'};
for(int i = 0;i < MM;i++)
{
a1[i] = random.nextInt(100)*(-1);
a2[i] = random.nextInt(100);
b1[i] = random.nextInt(100)*(-1);
b2[i] = random.nextInt(100);
cc[i] = random.nextInt(4);
}
//排除的分数题目
while(nn <= MM*(MM-1)/2)
{
for(int iii = 0;iii < MM;iii++)
{
nn++;
for(int ii = iii+1;ii < MM;ii++)
{
nn++;
if( (cc[ii] == 3 && b1[ii] == 0) || b2[ii] == 0 || a2[ii] == 0 || (a1[ii] >= a2[ii]) || (b1[ii] >= b2[ii]) || (a1[ii] == a1[iii] && b1[ii] == b1[iii] && a2[ii] == a2[iii] && b2[ii] == b2[iii] && cc[ii] == cc[iii]))
{
a1[ii] = random.nextInt(100)*(-1);
a2[ii] = random.nextInt(100);
b1[ii] = random.nextInt(100)*(-1);
b2[ii] = random.nextInt(100);
cc[ii] = random.nextInt(4);
}
}
}
}
//输出题目
for(int jj = 0;jj < MM;jj++)
{
System.out.println("("+a1[jj]+"/"+a2[jj]+")"+dd[cc[jj]]+"("+b1[jj]+"/"+b2[jj]+")"+"=");
}
}
}

public static void main(String[] args) {

int [] a = new int [5];
Scanner scanner = new Scanner(System.in); //定义输入变量
int o =1;
while(o == 1)
{
System.out.println("1.乘除");//输出界面
System.out.println("2.括号(最多10个数参与计算)");//输出界面
System.out.println("3.数值范围");//输出界面
System.out.println("4.加减有负数");//输出界面
System.out.println("5.加减");//输出界面
System.out.println("请输入操作前的数字:");//输出界面
a[0] = scanner.nextInt();
if(a[0] == 1)
{
chengchu();
}
if(a[0] == 5)
{
jiajian();
}
if(a[0] == 3)
{
fanwei();
}
if(a[0] == 4)
{
fushu();
}
if(a[0] == 2)
{
kuohao();
}
}

 

}

}

2.截图:

3.设计思想:根据不同的要求进行相应的编写。

 4.

 

 只有周五上课,周一写代码。

 

转载于:https://www.cnblogs.com/anheidijia-123/p/6544728.html

你可能感兴趣的文章
mysql 数据库插入语句之insert into,replace into ,insert ignore
查看>>
ConcurrentHashMap vs Collections.synchronizedMap()不同
查看>>
Linux 安装ibus极点五笔输入法备忘录
查看>>
jquery、js调用iframe父窗口与子窗口元素的方法整理
查看>>
MFC函数——CWnd::OnEraseBkgnd
查看>>
TrinityCore3.3.5环境搭建
查看>>
[转]《Hadoop基础教程》之初识Hadoop
查看>>
ArcGIS API for Silverlight地图加载众多点时,使用Clusterer解决重叠问题
查看>>
JavaScript - 时间函数
查看>>
node.js操作mysql数据库之增删改查
查看>>
总结的面试中常见65种应聘技巧回答
查看>>
Androidmanifest.xml在Android项目中的作用
查看>>
验证非法电话号码
查看>>
Android Parcelable和Serializable的区别,androidparcelable
查看>>
Axure JS弹窗提示部件
查看>>
A Study of WebRTC Security
查看>>
(原) windows下autohotkey的快捷键脚本编写
查看>>
javascript类型系统——Number数字类型
查看>>
[Informix] unload load
查看>>
Highcharts网页版
查看>>