尧图网络 高端网站定制 · 原创设计
免费咨询热线
400-888-6620
免费获取方案
练习练习练习
人机猜拳import java.util.Scanner;public class Qwe {public static void main(String[] args) {new Game().play();}}class User {private String name;private Scanner scanner new Scanner(System.in);private int choice;public User(String name) {this.name name;}public String getName() {return name;}public void game() {System.out.print(请出拳);choice scanner.nextInt();while (true) {if (choice 1) {System.out.println(你出拳剪刀);break;} else if (choice 2) {System.out.println(你出拳石头);break;} else if (choice 3) {System.out.println(你出拳布);break;} else {System.out.print(输入不合法请重新输入);choice scanner.nextInt();}}}public int getChoice() {return choice;}}class Computer {private int winCount;private int loseCount;private int total;private String fistName(int n) {if (n 1) return 剪刀;else if (n 2) return 石头;else return 布;}private int judge(int userChoice, int computerChoice) {if (userChoice computerChoice) return 0;if ((userChoice 1 computerChoice 3)|| (userChoice 2 computerChoice 1)|| (userChoice 3 computerChoice 2)) return 1;else return -1;}public void computerGame(User user, String role) {winCount 0;loseCount 0;total 0;Scanner scanner new Scanner(System.in);String again;do {total;user.game();int computerChoice (int) (Math.random() * 3) 1;System.out.println(role 出拳 fistName(computerChoice));int result judge(user.getChoice(), computerChoice);if (result 1) {System.out.println(恭喜你赢了);winCount;} else if (result -1) {System.out.println(很遗憾你输了);loseCount;} else {System.out.println(平局);}System.out.print(是否继续 y/n );again scanner.next();} while (y.equals(again));}public int getWinCount() { return winCount; }public int getLoseCount() { return loseCount; }public int getTotal() { return total; }}class Game {private Scanner scanner new Scanner(System.in);public void play() {System.out.println(******************************** 猜拳 ,开始 ********************************);System.out.println(出拳规则1.剪刀 2.石头 3.布);System.out.print(请输入你的名字);String userName scanner.next();User user new User(userName);String roundAgain;do {System.out.print(请选择对方的角色1.刘备 2.孙权 3.曹操);String role null;while (true) {int choice scanner.nextInt();if (choice 1) role 刘备;else if (choice 2) role 孙权;else if (choice 3) role 曹操;if (role ! null) {System.out.println(你选择了 role 对敌);break;}System.out.print(输入错误请重新输入);}System.out.print(要开始吗 y/n );String start scanner.next();if (!y.equals(start)) {System.out.println(已退出);break;}Computer computer new Computer();computer.computerGame(user, role);int userWin computer.getWinCount();int compWin computer.getLoseCount();int total computer.getTotal();if (userWin compWin) {System.out.println(userName VS role 比分为 userWin : compWin 对战场次 total 把 userName 胜利);} else if (compWin userWin) {System.out.println(userName VS role 比分为 userWin : compWin 对战场次 total 把 role 胜利);} else {System.out.println(userName VS role 比分为 userWin : compWin 对战场次 total 把平局);}System.out.print(是否开启下一轮 y/n );roundAgain scanner.next();} while (y.equals(roundAgain));System.out.println(游戏结束);}}怪物模块class Monster {String name;int blood;int attackPower;int defence;public void attack() { System.out.println(攻击); }public void move() { System.out.println(移动); }}class Goblin extends Monster {int rage;Overridepublic void attack() {System.out.println(哥布林正在用石头攻击);}Overridepublic void move() {System.out.println(哥布林缓慢移动);}}class CatDemon extends Monster {Overridepublic void attack() {System.out.println(猫妖正在用爪子攻击你);}Overridepublic void move() {System.out.println(猫妖跳着移动);}}抽象绘制abstract class All {String x;String y;String color;public abstract void draw();}class Line extends All {String finalCoordinate;String originalCoordinate;Overridepublic void draw() { System.out.println(绘制线条); }}class Rectangle extends All {int length;int width;Overridepublic void draw() { System.out.println(绘制矩形); }}class Circle extends All {int r;Overridepublic void draw() { System.out.println(绘制圆形); }}class Test1 {static public void testpage() {All[] a new All[3];a[0] new Line();a[1] new Circle();a[2] new Rectangle();for (int i 0; i a.length; i) {a[i].draw();}}}员工管理abstract class All {String x;String y;String color;public abstract void draw();}class Line extends All {String finalCoordinate;String originalCoordinate;Overridepublic void draw() { System.out.println(绘制线条); }}class Rectangle extends All {int length;int width;Overridepublic void draw() { System.out.println(绘制矩形); }}class Circle extends All {int r;Overridepublic void draw() { System.out.println(绘制圆形); }}class Test1 {static public void testpage() {All[] a new All[3];a[0] new Line();a[1] new Circle();a[2] new Rectangle();for (int i 0; i a.length; i) {a[i].draw();}}}Employees[] employees new Employees[100];for (int i 0; i employees.length; i) {if (Math.random() 0.5) {employees[i] new Manager();} else {employees[i] new Coder();}}for (Employees e : employees) {e.work();}面积形状class Shape {public double area() { return 0; }public void show() { System.out.println(这是一个形状); }}class Circles extends Shape {double radius;public Circles(double radius) { this.radius radius; }Overridepublic double area() { return Math.PI * radius * radius; }Overridepublic void show() { System.out.println(这是一个圆形); }}class Rectangles extends Shape {double length;double width;public Rectangles(double length, double width) {this.length length;this.width width;}Overridepublic void show() { System.out.println(这是一个矩形); }Overridepublic double area() { return length * width; }}class Test2 {static public void test2() {Scanner scanner new Scanner(System.in);System.out.println(请输入半径);double r scanner.nextDouble();System.out.println(请输入长和宽);double a scanner.nextDouble();double b scanner.nextDouble();Shape[] shape new Shape[2];shape[0] new Circles(r);shape[1] new Rectangles(a, b);for (int i 0; i shape.length; i) {System.out.println(shape[i].area());shape[i].show();}}}数组扩容class M {static public void array() {int i 0;Scanner scanner new Scanner(System.in);int[] arr new int[2];System.out.println(请输入数字-1结束);while (true) {int b scanner.nextInt();if (b -1) {System.out.println(结束输入);break;}arr[i] b;i;if (i arr.length) {arr Arrays.copyOf(arr, arr.length * 2);}}// 只打印有效部分for (int j 0; j i; j) {System.out.print(arr[j] );}}}学生管理class Student {private String name;private int age;private int score;public Student(int age, String name, int score) {this.age age;this.name name;if (score 0 || score 100) {System.out.println(成绩不合法);} else {this.score score;}}public int getAge() { return age; }public String getName() { return name; }public int getScore() { return score; }public void setAge(int age) { this.age age; }public void setName(String name) { this.name name; }public void setScore(int score) {if (score 0 || score 100) {System.out.println(成绩不合法);} else {this.score score;}}public void show() {System.out.println(姓名 name 年龄 age 成绩 score);}}
RELATED

相关推荐

Flask构建残障社区服务平台的技术实践

Flask构建残障社区服务平台的技术实践

1. 项目背景与核心需求社区残障人士服务平台的开发源于一个普遍存在却常被忽视的社会痛点——残障群体在获取社区服务时面临的信息不对称和物理障碍。传统服务模式往往需要残障人士主动到指定地点登记需求,这种"被动等待"的服务机制对行动不便者极不友好。…

📅 2026/9/25 12:04:31
11. 类和动态内存分配

11. 类和动态内存分配

类和动态内存分配动态内存和类在类中使用 new 和 delete 来动态管理内存,可以让程序在运行时(而非编译时)决定内存分配。在类构造函数中使用 new,需要额外执行一系列步骤:扩展析构函数、编写额外的类方法来帮助正确完成…

📅 2026/9/25 12:05:23
车载以太网(0)

车载以太网(0)

专栏更新说明从今天开始我将不定期的更新车载以太网的相关知识和资料,以及我在工作中遇到问题的一些解决方案和思考路径。我本身工作比较忙,所以希望自己能每周更新至少一篇到两篇专栏文章,希望可以对刚进入车载以太网的同学或者在行业中但是…

📅 2026/9/25 2:16:50
MORE NEWS

更多资讯

📰

Kerberos委派攻击全解析:从非约束委派到RBCD与Spooler触发

一次授权内网测试里,我在客户现场盯着一台普通文件服务器看了很久。目标域有三千多用户,域控制器权限划分得比较谨慎,常规漏洞没抓到什么机会。后面想起来翻了一下LDAP里的委派配置,发现这台文件服务器竟然开了非约束委派&#xf…

📰

无需上传IPA的在线砸壳工具dumpipa.com实测与原理分析

1. 砸壳这件事,到底在解决什么问题做iOS逆向或者安全研究的朋友,对“砸壳”这个词肯定不陌生。简单说,App Store下载的IPA包是经过加密的,可执行文件被一层“壳”包住,直接拖进IDA或者Hopper看,全是乱码。你…

📰

4.1存储器概述

1.存储器概述2.存储器的分类 2.1:存储器的分类2.2:几种常见的存储器3.存储器的性能指标 3.1:存储容量3.1:存取速度4.存储系统的层次结构5.主存的基本结构6.主存中数据的存放 6.1:机器字长与存储字长的区别6.2:地址访问模式6.3&…

📰

OpenClaw Windows 一键部署:虾壳云定制优化包配 TaoToken 省去环境配置

/* MD / 富文本中的 .toc(含博客园搬家等嵌套结构);.toc-box 在侧栏,不受影响 */#content_views .toc,/* 编辑器常在目录前后插入空 p(:empty 仍占 20px),一并去掉避免顶空隙 */#content_views.markdown_views > p:empty:has(+ .toc),#content_views.markdown_views …

📰

Atlas 300V 24G部署YOLO实战:模型转换、环境搭建与性能调优

1. 从热搜说起:Atlas 300V 24G到底是不是运算加速卡最近后台收到不少朋友在问同一个问题:“Atlas 300V 24G是运算加速卡吗?”说实话,这个问题我当年第一次接触华为Atlas产品线时也困惑过,因为市面上叫“加速卡”的东西…

📰

ESPnet2 中 LibriSpeech-100 的 ASR 配方全解析:从 E-Branchformer 到多任务解码实践

人工智能语音音频深度学习NLP 【免费下载链接】espnet End-to-End Speech Processing Toolkit 项目地址: https://gitcode.com/gh_mirrors/es/espnet 点击查看 免费下载 导读 本文基于 ESPnet 开源语音处理工具包的 LibriSpeech-100 数据集 ASR 配方(e…

TODAY

今日更新

THIS WEEK

本周精选

THIS MONTH

本月热门

读完文章,想聊聊您的网站?

告诉我们您的行业与需求,资深顾问一对一梳理方案与报价,全程免费。

📞 💬