二柱子出题程序


import java.util.Scanner; import java.util.ArrayList; public class copy { public static int suiji(int min, int max) { int S; S = (int)(min+Math.random()*(max-min+1)); return S; } public static int suiji() { int S; S = (int)(1+Math.random()*(999-1+1)); return S; } public static int suijifuhao() { int S; S = (int)(1+Math.random()*(4-1+1)); return S; } public static int suijifuhao1() { int S; S = (int)(1+Math.random()*(2-1+1)); return S; } public static boolean chachong(ArrayList<String> S,String T) { String temp; for(int i = 0;i < S.size();i++) { temp = S.get(i); if(temp.equals(T)) { return false; } } return true; } public static String chutishu(int min,int max)//输出运算数 { int temp = 0; temp = suiji(min, max); String T; T = String.valueOf(temp); return T; } public static String chutifuhao(int l) //输出运算符 { int temp = 0; //符号判别变量 String T; if(l == 1) { temp = suijifuhao(); } else { temp = suijifuhao1(); } switch (temp) { case 1: { T = String.valueOf("+"); break; } case 2: { T = String.valueOf("-"); break; } case 3: { T = String.valueOf("*"); break; } case 4: { T = String.valueOf("/"); break; } default:T = null; } return T; } public static void main(String[] args) { ArrayList<String> S = new ArrayList<>(); Scanner sc = new Scanner(System.in); String T1; String T = null; int a, b; a = 1; b = 1; int temp = 0; int number = 0; System.out.println("请输入您要定制的个数"); number = sc.nextInt(); System.out.println("请输入需要几个数运算"); int n = 0; n = sc.nextInt(); System.out.println("是否有乘除运算,有输入1,无输入0"); int l = 0; l = sc.nextInt(); System.out.println("请输入随机数据的范围 最小值 最大值"); int min = 0; int max = 0; min = sc.nextInt(); max = sc.nextInt(); int p = 0; //随即括号 int j = 0; //括号计数器 int p1 = 0; //随即括号 for(int i = 1;i <= number;i++) { p = suiji(); p1 = suiji(); j = 0; T = " "; for(int m = 1; m <= n+n-1; m++) { if(!(m%2==0)) { T = T + chutishu(min,max); } else { T = T + chutifuhao(l); } if(p % 2==0 && p % 3 == 0 && m % 2 ==0 ) { T1 = String.valueOf("("); T = T + T1; j++; continue; } if(p1 % 2==0 && p1 % 3 == 0 && m % 2 ==0 && j > 0) { T1 = String.valueOf(")"); T = T + T1; j--; } } while(!(j==0)) { T1 = String.valueOf(")"); T = T + T1; j--; } T1 = String.valueOf("="); T = T + T1; if(chachong(S, T)) { S.add(T); } } for(int s = 0;s < S.size();s++) { System.out.println(S.get(s)); } } }

实现功能

1、可定制(数量):输入大的出题数量值;

2、定制操作数的个数;

3、定制是否有乘除法;

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

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

posted @ 2021-09-25 18:48  软工小蜗牛  阅读(82)  评论(0编辑  收藏  举报