用java编写程序 课题:算术运算测试
课题:算术运算测试功能要求:该程序用字符界面实现十道100以内加减法数学题,能根据题目计算出答案,与输入答案对比,判断做题是否正确,最后计算分数。界面要求:用字符界面实现...
课题:算术运算测试
功能要求:该程序用字符界面实现十道100以内加减法数学题,能根据题目计算出答案,与输入答案对比,判断做题是否正确,最后计算分数。
界面要求:用字符界面实现、也可用图形界面实现。
将程序发到1084647004@qq.com邮箱,谢谢! 展开
功能要求:该程序用字符界面实现十道100以内加减法数学题,能根据题目计算出答案,与输入答案对比,判断做题是否正确,最后计算分数。
界面要求:用字符界面实现、也可用图形界面实现。
将程序发到1084647004@qq.com邮箱,谢谢! 展开
3个回答
展开全部
你好,按照你的要求代码如下,可以直接运行
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class test {
public static void main(String[] args) {
int count = 0;
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
for (int i = 0; i < 10; i++) {
int a = (int) (Math.random() * 100);
int b = (int) (Math.random() * 100);
int c = (int) (Math.random() * 2);
int r = 0;
switch (c) {
case 0:
if (a + b >= 100) {
a = 100 - b;
}
System.out.print(a + " + " + b + " = ");
r = a + b;
break;
case 1:
if (a < b) {
int t = a;
a = b;
b = t;
}
System.out.print(a + " - " + b + " = ");
r = a - b;
}
int input;
try {
input = Integer.valueOf(in.readLine());
} catch (Exception e1) {
System.out.println("答案错误\n");
continue;
}
if (input == r) {
count++;
System.out.println("答案正确\n");
} else {
System.out.println("答案错误\n");
}
}
if (null != in) {
try {
in.close();
} catch (IOException e) {
e.printStackTrace();
}
}
System.out.println("答对数量:" + count + "\n得分: " + count * 10);
}
}
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class test {
public static void main(String[] args) {
int count = 0;
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
for (int i = 0; i < 10; i++) {
int a = (int) (Math.random() * 100);
int b = (int) (Math.random() * 100);
int c = (int) (Math.random() * 2);
int r = 0;
switch (c) {
case 0:
if (a + b >= 100) {
a = 100 - b;
}
System.out.print(a + " + " + b + " = ");
r = a + b;
break;
case 1:
if (a < b) {
int t = a;
a = b;
b = t;
}
System.out.print(a + " - " + b + " = ");
r = a - b;
}
int input;
try {
input = Integer.valueOf(in.readLine());
} catch (Exception e1) {
System.out.println("答案错误\n");
continue;
}
if (input == r) {
count++;
System.out.println("答案正确\n");
} else {
System.out.println("答案错误\n");
}
}
if (null != in) {
try {
in.close();
} catch (IOException e) {
e.printStackTrace();
}
}
System.out.println("答对数量:" + count + "\n得分: " + count * 10);
}
}
追问
算术运算测试 怎么改成图形界面啊?
展开全部
public class Test {
public static void main(String[] args) {
Random rd = new Random();
int d = 0;
for (int i = 0; i < 10; i++) {
int a = rd.nextInt(100);
int b = rd.nextInt(100);
int c = rd.nextInt(2);
if (c == 0) {
d = a + b;
System.out.println(a + "+" + b + "=" + d);
} else if (c == 1) {
d = a - b;
System.out.println(a + "-" + b + "=" + d);
}
}
}
}
public static void main(String[] args) {
Random rd = new Random();
int d = 0;
for (int i = 0; i < 10; i++) {
int a = rd.nextInt(100);
int b = rd.nextInt(100);
int c = rd.nextInt(2);
if (c == 0) {
d = a + b;
System.out.println(a + "+" + b + "=" + d);
} else if (c == 1) {
d = a - b;
System.out.println(a + "-" + b + "=" + d);
}
}
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
楼上写的程序没有实现100以内这个条件,因为运行的时候,出现这样的题目123+56
把代码中的 a = 2 * a + b - 100; b = a + 2 * b - 100; 改成a = a + b - 100; b = a + b - 100
后就可以实现楼主的要求。
把代码中的 a = 2 * a + b - 100; b = a + 2 * b - 100; 改成a = a + b - 100; b = a + b - 100
后就可以实现楼主的要求。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询