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.
只有周五上课,周一写代码。