四则运算出题系统,java
2024-09-22 10:40:12
程序设计思想:
首先通过判断选择计算的范围,然后用随机数生成两个随机数,定义另一个数,将两个随机数计算得到的值赋给定义的数
程序代码:
package Kaos1;
import java.util.Random;
import java.util.Scanner;
public class Test{
public static void main(String[] args) {
int m=1;
int a=0,b=0,c=0,d=0,e=0;
int x=0;
String p="",q="";
Random random = new Random(); for(int w=0;w<10000000;w++)
{
System.out.println("请输入选择:1、整数 2、真分数 3、退出程序");
Scanner sc = new Scanner(System.in);
int x1 = sc.nextInt();
{
for(int i=0;i<30;i++)
{
a = random.nextInt(100);
b=random.nextInt(100);
c=random.nextInt(4);
if(c==0)
{System.out.println(a+"+"+b+"=");}
if(c==1)
{System.out.println(a+"-"+b+"=");}
if(c==2)
{System.out.println(a+"*"+b+"=");}
if(c==3)
{
if(b!=0)
{
System.out.println(a+"/"+b+"=");
}
if(b==0)
{i--;}
} }
}
if(x1==2)
{
for(int r=0;r<30;r++)
{
a = random.nextInt(100);
b=random.nextInt(100);
d = random.nextInt(100);
e=random.nextInt(100);
c=random.nextInt(4);
if((a>=b&&b!=0)||a==0)
{
p=a+"/"+b;
}
else
{
p=b+"/"+a;
}
if((d>=e&&e!=0)||d==0)
{
q=d+"/"+e;
}
else
{
q=e+"/"+d;
}
if(c==0)
{
System.out.println(p+"+"+q);
}
if(c==1)
{
System.out.println(p+"-"+q);
}
if(c==2)
{
System.out.println(p+"*"+q);
}
if(c==3)
{
if(d==0||e==0)
{
r--;
}
else
{
System.out.println(p+"/"+q);
}
}
}
}
if(x1==3)
{
break;
}
}
}
}
运行结果截图:
上课的时候没有完成,是随机生成30道题目的时候出现了问题。
课下了专研了一下完成了基本功能
最新文章
- 取两个String数组的交集
- 读 [The Root of Lisp]
- Mac下安装 PIL
- 【MySQL】InnoDB: Error: checksum mismatch in data file 报错
- 每天一个shell知识--数组
- ThinkPHP讲解(七)——修改删除
- 2015_WEB页面前端工程师_远程测题_东方蜘蛛_1
- 【报错】java.lang.RuntimeException: Invalid action class configuration that references an unknown class named [xxxAction]
- POJ - 3666 Making the Grade(dp+离散化)
- RAS 加密 解密
- SQLServer 自动循环归档分区数据脚本
- 《css定位 position》课程笔记
- 笔记:Spring Cloud Feign Ribbon 配置
- python基础知识练习题(一)
- Nowcoder contest 370B Rinne Loves Graph 【分层图最短路】
- hibernate JPA 使用懒加载时代理对象
- 从Firebird2.5 迁移到 Firebird3.0 手记
- Ntfs 下的链接符号创建
- GDI+编程小结
- 关于有时候导入maven项目时候报错(有红色叹号,类中导入的包提示";the import java.util cannot be resolve,";)
热门文章
- 数组 -----JavaScript
- Oracle 数据库、实例、表空间、用户、数据库对象
- BZOJ3398: [Usaco2009 Feb]Bullcow 牡牛和牝牛(dp)
- mysql查询哪个表数据量最大
- rsync常用命令和使用方法
- 基于flash-marker.js 的地图标注闪烁代码调试
- 安装并配置多实例Mysql数据库
- 第二章JavaScript 函数和对象
- win7在某个盘或文件夹中出现右键只能新建文件夹的情况 (2012-12-28-bd 写的日志迁移
- 26.VUE学习之--提交表单不刷新页面,事件修饰符之使用$event与prevent修复符操作表单