java 简单考试系统 ——java程序设计
import java.util.Random;
import java.util.Scanner;
public class shuru {
public static void main(String[] args) {
System.out.print("java 小学计算题考试\n");
while (true) {
int i, n, shu1, shu2, temp;
char zifu = 0;
int shuru;
int ceshi = 0;
int panduan=0;
Scanner in = new Scanner(System.in);
Random rand1 = new Random();
n = rand1.nextInt(4); //0-3
shu1 = rand1.nextInt(101);
shu2 = rand1.nextInt(101);
switch (n) {
case 0:
zifu = '+';
break;
case 1:
zifu = '-';
break;
case 2:
zifu = '*';
break;
case 3:
zifu = '/';
break;
}
if (zifu == '/' && shu2 > shu1) {
temp = shu1;
shu1 = shu2;
shu2 = temp;
}
if (shu1 % shu2 != 0) //在除法算式中,除号后面的数叫做除数,除号前面的数叫做被除数。
{
shu1 = (shu1 - (shu1 % shu2));
}
System.out.print(shu1);
System.out.print(zifu);
System.out.print(shu2 + "=");
long startTime=System.currentTimeMillis(); //获取开始时间
shuru = in.nextInt();
long endTime=System.currentTimeMillis(); //获取结束时间
System.out.println("程序运行时间: "+(endTime-startTime)/1000+"s");
switch (n) {
case 0:
ceshi = shu1 + shu2;
break;
case 1:
ceshi = shu1 - shu2;
break;
case 2:
ceshi = shu1 * shu2;
break;
case 3:
ceshi = shu1 / shu2;
break;
}
if(shuru==ceshi)
System.out.print("正确\n");
else
System.out.print("错误\n你连小学的题都算不对吗?\n本题的答案:"+ceshi+"\n");
System.out.print("继续吗?<yes/no>(输入1继续 输入0退出) ");
panduan=in.nextInt();
if(panduan==0)
break;
}
}
}
运行效果
水平有限,如有错误,还望大神指正;(^_−)☆
点个赞白( • ̀ω•́ )✧