zoukankan      html  css  js  c++  java
  • 猜拳游戏

     1 import java.util.Scanner;
     2 
     3 public class caiquan {
     4     public static void main(String[] args) {
     5         Scanner sc = new Scanner(System.in);
     6         for (;;) {
     7             int person = 0;
     8             for (;;) {
     9                 System.out.println("请输入你的选择(1--石头 2--剪刀 3--布)");
    10                 person =sc.nextInt();
    11                 if (person == 1) {
    12                     System.out.println("你的选择是:石头");
    13                     break;
    14                 } else if (person == 2) {
    15                     System.out.println("你的选择是:剪刀");
    16                     break;
    17                 } else if (person == 3) {
    18                     System.out.println("你的选择是:布");
    19                     break;
    20                 } else {
    21                     System.out.println("你的选择无效");
    22                     continue;
    23                 }
    24             }
    25 
    26             int marchine;
    27             for (;;) {
    28                 System.out.println("电脑输入的选择(1--石头 2--剪刀 3--布)");
    29                 marchine = (int) (Math.random() * 4);
    30                 if (marchine == 1) {
    31                     System.out.println("电脑的选择是:石头");
    32                     break;
    33                 } else if (marchine == 2) {
    34                     System.out.println("电脑的选择是:剪刀");
    35                     break;
    36                 } else if (marchine == 3) {
    37                     System.out.println("电脑的选择是:布");
    38                     break;
    39                 } else {
    40                     System.out.println("电脑的选择无效");
    41                     continue;
    42                 }
    43             }
    44 
    45             if (person == 1 && marchine == 1 || person == 2 && marchine == 2
    46                     || person == 3 && marchine == 3) {
    47                 System.out.println("平局!");
    48             } else if (person == 1 && marchine == 2 || person == 2
    49                     && marchine == 3 || person == 3 && marchine == 1) {
    50                 System.out.println("你赢了!");
    51             } else if (person == 1 && marchine == 3 || person == 2
    52                     && marchine == 1 || person == 3 && marchine == 2) {
    53                 System.out.println("很遗憾,你输了!");
    54             }
    55 
    56             boolean bool = false;
    57             for (;;) {
    58                 System.out.print("是否继续下一局(Y/N):");
    59                 String b = sc.next();
    60                 if (b.equals("Y")) {
    61                     bool = true;
    62                     break;
    63                 } else if (b.equals("N")) {
    64                     bool = false;
    65                     break;
    66                 } else {
    67                     continue;
    68                 }
    69             }
    70             if (bool == true) {
    71                 
    72             } else {
    73                 break;
    74             }
    75             System.out.println("
    "); 
    76         }
    77     }
    78 }
  • 相关阅读:
    网易编程题——小易喜欢的单词
    Effective C++ 条款12:复制对象时勿忘其每一个成分
    Effective C++ 条款11:在operator=中处理"自我赋值"
    STM32-通用定时器基本定时功能
    GPIO_Mode
    STM32的ADC编程方法
    STM32的ADC采样与多通道ADC采样
    网络子系统
    linux网络子系统内核分析
    Linux 中高效编写 Bash 脚本的 10 个技巧
  • 原文地址:https://www.cnblogs.com/1020182600HENG/p/5867511.html
Copyright © 2011-2022 走看看