当前位置: 首页 > news >正文

生成算数问题*30

package pack1;

public class Suanshi {
private int can1;
private int can2;
private int result;
private char op;

public int getCan1() {        return can1;             
}                            public void setCan1(int can1)this.can1 = can1;        
}                            public int getCan2() {        return can2;             
}                            public void setCan2(int can2)this.can2 = can2;        
}                            public int getResult() {      return result;           
}                            public void setResult(int resthis.result = result;    
}                            public char getOp() {         return op;               
}                            public void setOp(char op) { this.op = op;            
}                            public Suanshi(int can1, int this.can1 = can1;        this.can2 = can2;        this.result = result;    this.op = op;            }                            
public int result1(){         if(op=='+')              return can1+can2;    else if(op=='-')         return can1-can2;    else if(op=='*')         return can1*can2;    else if(op=='/')         return can1/can2;    else                     return 0;            
}                            

}
//--------------------------
package pack1;

import java.math.BigInteger;
import java.util.Random;
import java.util.Scanner;

public class Test1 {
static Suanshi[] suanshi = new Suanshi[10086];
static int[] result = new int[10086];
static int arr1[] = new int[10086];
static int dui=0,cuo=0;
public static void menu() {
System.out.println("1.生成题目");
System.out.println("2.输出答案");
System.out.println("3.判断对错");
System.out.println("4.退出");
}

static Scanner sc = new Scanner(System.in);public static void main(String[] args) {int n = 0;while (true) {menu();n = sc.nextInt();switch (n) {case 1:generate();break;case 2:print();break;case 3:judge();break;case 4:System.exit(0);break;default:System.out.println("输入错误");break;}}}private static void judge() {System.out.println("正确"+dui+"个");System.out.println("错误"+cuo+"个");}private static void print() {for(int i=1;i<=30;i++){System.out.println(suanshi[i].getCan1()+" "+suanshi[i].getOp()+" "+suanshi[i].getCan2()+"="+suanshi[i].getResult());}}private static void generate() {Random rand1 = new Random();Random rand2 = new Random();Random rand3 = new Random();int a = rand3.nextInt(4) + 1;for (int i = 1; i <= 30; i++) {int x = rand1.nextInt(10) + 1;int y = rand2.nextInt(10) + 1;if (a == 1) {suanshi[i] = new Suanshi(x, y, x + y, '+');} else if (a == 2) {suanshi[i] = new Suanshi(x, y, x - y, '-');} else if (a == 3) {suanshi[i] = new Suanshi(x, y, x * y, '*');} else if (a == 4) {suanshi[i] = new Suanshi(x, y, x / y, '/');}}for(int i=1;i<=30;i++){System.out.println(suanshi[i].getCan1()+" "+suanshi[i].getOp()+" "+suanshi[i].getCan2()+"=");result[i]=sc.nextInt();if(result[i]==suanshi[i].result1()){System.out.println("正确");dui++;}else{System.out.println("错误");cuo++;}}}

}

http://www.rkmt.cn/news/13095.html

相关文章:

  • 6379:统计学生信息(使用动态链表完成)
  • 使用IOT-Tree Server通过FINS协议连接欧姆龙CP2E-N系列PLC - 详解
  • 实用指南:疑难bug之正确处理InterruptedException
  • GNSS精度判断和协方差矩阵 - MKT
  • Insightly模板页面存储型XSS漏洞分析与复现
  • CF2065D Skibidus and Sigma
  • 微信二次开发个人号api
  • 深入解析:神经网络二分类任务详解:前向传播与反向传播的数学计算
  • 关于Leetcode 812题的简单思考
  • Python 潮流周刊#121:工程师如何做出高效决策?
  • 【远程桌面】运维强推设备之远程控制软件RustDesk 1.4.1 全面指南:开源远程桌面的终极解决方案
  • 第六篇
  • 6378:删除数组中的元素(链表)
  • 详解 Kubernetes 命令:kubectl exec -it nginx -- bash 及实战场景 - 教程
  • 【08】海康相机C#开发——在海康MVS的**C#实例中添加控件报错**“`不能在本地化模式下添加组件。在 Language 属性中选择”(默认)”以返回到默认格式,然后添加组件`” - 实践
  • # Windows CMD 基本指令参考手册
  • P13019 [GESP202506 八级] 树上旅行
  • 完整教程:负载均衡式的在线OJ项目编写(二)
  • 记录这辈子见到的第一道从上到下的树上倍增
  • 06.容器存储 - 教程
  • 深入解析:【Linux】进程概念(六):进程地址空间深度解析:虚拟地址与内存管理的奥秘
  • 深入解析:Metal - 5.深入剖析 3D 变换
  • 油猴脚本(tampermonkey)离线安装文件下载,带油猴(tampermonkey)插件清单
  • 详细介绍:【汽车篇】基于深度学习的2D+3D整车漆面外观缺陷检测
  • 深入解析:网线传输距离限制 | 理论基础 / 实际应用 | 双绞线分类与特性 / 水晶头制作
  • 2025年试验机品牌权威推荐榜:聚焦 TOP5 专精特新企业,疲劳试验机,压力试验机,液压万能试验机等设备技术实力与口碑解析!
  • [2025.9.27鲜花] 私たちもう一生 分かり合えないと 分かっていたでしょう
  • 2025年岗亭厂家最新权威推荐榜:内蒙古门卫室岗亭,售货岗亭,值班岗亭,保安岗亭,低噪声岗亭选购指南
  • SPI和普通设计模式区别
  • 混元开源之力:spring-ai-hunyuan 项目功能升级与实战体验 - 指南