实现一个小学生数学考试系统

功能:

1.学生输入题的数量。

2.系统随机产生1-100的四则运算随机式。

3.学生输入答案,系统判断正误。正确得一分,错误不得分

4.打印出最终成绩

代码:

import java.util.Scanner;
public class ss {

public static void main(String[] args) {
kaishi();
}
public static int suijishu() //产生随机数
{
int x=(int)(Math.random ()*(100-1+1));
return x;
}

public static char suijifuhao()//随机符号
{
int x=(int)(Math.random ()*(3-1+1));
if (x==1) return '+';
if (x==2) return '-';
if (x==3) return '*';
else return '/';
}
public static int yunsuan()//产生运算式
{
int x=suijishu();
int x1=suijishu();
char y=suijifuhao();
System.out.println("运算式:"+x+y+x1);
if(y=='+')return x+x1;
if(y=='-')return x-x1;
if(y=='*')return x*x1;
else return Math.round (x/x1);
}
public static boolean jiancha()//检查是否正确
{
int sr,zq;zq=yunsuan();
System.out.print("输入答案:");
Scanner sc=new Scanner(System.in);
sr=sc.nextInt();
if(sr==zq){System.out.println("正确!");return true;}
else System.out.println("错误!");return false;

}
public static int chengji(int cishu)
{
int cj=0;
for(int i = 0; i < cishu; i++)
{
if (jiancha()) cj+=1;
else continue;
}
return cj;
}
public static void kaishi()
{
int x = 0;
System.out.print("输入题目数量:");
Scanner sc=new Scanner(System.in);
x=sc.nextInt();
System.out.println("得分:"+chengji(x));
}
}

  

转载于:https://www.cnblogs.com/231520deng/p/7698112.html

  • 1
    点赞
  • 14
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值