-
Notifications
You must be signed in to change notification settings - Fork 89
/
Copy pathMathExam6308.java
139 lines (99 loc) · 3.38 KB
/
MathExam6308.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
package com.PSP6308;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Scanner;
public class MathExam6308 {
public static void main(String[] args) throws Exception{ Scanner s=new Scanner(System.in);
System.out.println("请问你是1年级还是2年级:");
int n=s.nextInt();
if(n==1) {
show1();
}
if(n==2) {
show2();
}
}
public static void show1() throws IOException {
File file = new File("out.txt");
FileWriter fw = new FileWriter(file);
BufferedWriter bw1 = new BufferedWriter(fw);
Scanner s=new Scanner(System.in);
System.out.println("请输入一个正整数:");
int n=s.nextInt();
System.out.println("即将生成"+n+"道题目");
String [] arry = new String[n];
int [] answer =new int[n];
for (int i = 0; i < n; i++) {
int x=0+(int)(Math.random()*2);
if(x==0) {
int x1=0+(int)(Math.random()*100);
int x2=0+(int)(Math.random()*100);
if(x1+x2>100) {
if(x1>50) x1=x1-50;
if(x2>50) x2=x2-50;
}
arry[i]=x1+"+"+x2+"=";
answer[i]=(x1+x2);
bw1.write(arry[i]);
bw1.newLine();
}
else{
int x1=0+(int)(Math.random()*100);
int x2=0+(int)(Math.random()*100);
if(x1<x2)
{int t=0;t=x1;x1=x2;x2=t;}
arry[i]=x1+"-"+x2+"=";
answer[i]=(x1-x2);
bw1.write(arry[i]);
bw1.newLine();
}}
bw1.write(("-------------标准答案--------------"));
bw1.newLine();
for (int i1 = 0; i1<n; i1++) {
bw1.write((arry[i1]+answer[i1]));
bw1.newLine();
}bw1.close();
}
public static void show2() throws IOException {
File file = new File("out.txt");
FileWriter fw = new FileWriter(file);
BufferedWriter bw2 = new BufferedWriter(fw);
Scanner s=new Scanner(System.in);
System.out.println("请输入一个正整数:");
int n=s.nextInt();
System.out.println("即将生成"+n+"道题目");
String [] arry = new String[n];
int [] answer =new int[n];
String [] yushu = new String[n];
for (int i = 0; i < n; i++) {
int x=0+(int)(Math.random()*2);
if(x==0) {
int x1=0+(int)(Math.random()*10);
int x2=0+(int)(Math.random()*10);
arry[i]=x1+"*"+x2+"=";
answer[i]=(x1*x2);
bw2.write(arry[i]);
bw2.newLine();
}
else{
int x1=1+(int)(Math.random()*10);
int x2=1+(int)(Math.random()*10);
if(x1<x2)
{int t=0;t=x1;x1=x2;x2=t;}
arry[i]=x1+"/"+x2+"=";
answer[i]=(x1/x2);
yushu[i]="余数为"+x1%x2;
bw2.write(arry[i]);
bw2.newLine();
}}
bw2.write(("-------------标准答案--------------"));
bw2.newLine();
for (int i1 = 0; i1<n; i1++) {
bw2.write((arry[i1]+answer[i1]+yushu[i1]));
bw2.newLine();
}bw2.close();
}
}