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 }
  • 相关阅读:
    Documentum之基础(1)
    tomcat部署项目,war包问题[转]
    AD与LDAP区别
    Microsoft Visual Studio2010--此时无足够的可用内存,无法满足操作的预期要求,可能是由于虚拟地址空间碎片造成的。请稍后重试。
    Oracle 11g服务器安装详细步骤
    Oracle 11g 密码永不过期设置
    oracle 11g dbf数据文件从C盘迁移到D盘
    Swift 简介
    0Day 密码重置dede阿帕奇强制安装
    PS抠图教程_抠图小技巧_常用抠图小技巧_图片结构与配色
  • 原文地址:https://www.cnblogs.com/1020182600HENG/p/5867511.html
Copyright © 2011-2022 走看看