Loading

9月9日下午课堂测试

 

  1 import java.util.Scanner;
  2 import java.util.Random;
  3 
  4 public class news {
  5 public static void main(String[] args) {
  6 
  7 System.out.println("请输入总题目数量:");
  8 Scanner sc = new Scanner(System.in);
  9 int n = sc.nextInt();
 10 
 11 
 12 System.out.println("请输入每行题目数量:");
 13 Scanner sc1 = new Scanner(System.in);
 14 int n1 = sc1.nextInt();
 15 
 16 System.out.println("请输入数据最大范围:");
 17 Scanner sc2 = new Scanner(System.in);
 18 int n2 = sc2.nextInt();
 19 
 20 System.out.println("请输入是否有乘除(1为是0为否):");
 21 Scanner sc3 = new Scanner(System.in);
 22 int n3 = sc3.nextInt();
 23 
 24 System.out.println("请输入是否有括号(1为是0为否):");
 25 Scanner sc4 = new Scanner(System.in);
 26 int n4 = sc4.nextInt();
 27 
 28 System.out.println("请输入操作符数量:");
 29 Scanner sc5 = new Scanner(System.in);
 30 int n5 = sc5.nextInt();
 31 int n6 = ((n5*2)+2);
 32 
 33 int s1=0;
 34 
 35 for(int i=0;i<n;i++) {
 36 
 37 for(int i1=0;i1<n5;i1++) {braces(n4,n6);rams(n2);braces(n4,n6);symb(n3);}braces(n4,n6);rams(n2);braces(n4,n6);System.out.print("= ");
 38 
 39 s1++;
 40 x0=0;
 41 count=0;
 42 point1=0;
 43 
 44 if(s1==n1) {
 45 
 46 System.out.println(" ");
 47 s1=0;
 48 }
 49 }
 50 //braces(n4)
 51 }
 52 
 53 static int x0=0;
 54 static int count=0;
 55 static int point1=0;
 56 public static void braces(int t,int g) {
 57 
 58 if(t==1) {
 59 
 60 count++;
 61 int x=0;
 62 
 63 Random rand = new Random();
 64 x = rand.nextInt(2);
 65 
 66 if(x0==2) {
 67 
 68 if(x==1&&count<g&&count%2==0) {
 69 
 70 System.out.print(")");
 71 x0=3;
 72 
 73 }
 74 
 75 if(count==g&&x0!=3&&count%2==0) {
 76 
 77 System.out.print(")");
 78 x0=3;
 79 
 80 }
 81 
 82 if(count==(g-2)&&x0!=3&&point1==1) {
 83 
 84 System.out.print(")");
 85 x0=3;
 86 
 87 }
 88 }
 89 
 90 if(x0==1) {
 91 
 92 x0=2;
 93 
 94 }
 95 
 96 if(x0==0) {
 97 
 98 if(x==1&&count%2!=0) {
 99 
100 System.out.print("(");
101 x0=1;
102 if(count==1) {
103 point1=1;
104 }
105 }
106 }
107 }
108 
109 }
110 
111 public static void rams(int r) {
112 
113 Random rand = new Random();
114 
115 System.out.print(rand.nextInt(r));
116 
117 }
118 public static void symb(int x) {
119 
120 Random rand = new Random();
121 
122 if(x==1) {
123 
124 int m1 =rand.nextInt(4);
125 
126 if(m1==0) {
127 System.out.print("+");
128 }
129 if(m1==1) {
130 System.out.print("-");
131 }
132 if(m1==2) {
133 System.out.print("*");
134 }
135 if(m1==3) {
136 System.out.print("/");
137 }
138 }
139 else if(x==0) {
140 int m1 =rand.nextInt(2);
141 
142 if(m1==0) {
143 System.out.print("+");
144 }
145 if(m1==1) {
146 System.out.print("-");
147 }
148 }
149 }
150 }

课堂上没有做完,晚上才做完了。静下心来写还是不难的。

这次课堂测试让我感触良多,深刻意识到了自己的不足,认识到自己今后应该加倍努力

-ByAurora

posted @ 2022-09-10 10:41  冰稀饭Aurora  阅读(14)  评论(0编辑  收藏  举报