zoukankan      html  css  js  c++  java
  • 猜数游戏代码

    import java.util.Scanner;

    public class Namble1 {
    public static void main(String[] args) {
    int count = 1;
    System.out.println("游戏>登录");
    System.out.println("请输入用户名:");
    Scanner input = new Scanner(System.in);
    String name = "zhangsan";
    name = input.next();
    System.out.println("请输入密码:");
    String mima = "123456";
    mima = input.next();
    if ("zhangsan".equals(name)) {
    if ("123456".equals(mima)) {
    System.out.println("********************************************");
    System.out.println("游戏>登陆成功>猜数游戏");
    System.out.println("游戏开始——已随机生成一位17-97的数字");
    System.out.println("******************************************** ");
    int num;
    int randNum = (int) (Math.random() * (97 - 17+ 1) + 17);
    do {
    System.out.println("请第"+count+"输入您猜的数字:");
    num = input.nextInt();
    if (num > randNum) {
    System.out.println("太大了...");
    }else if (num<randNum){
    System.out.println("太小了...");
    }
    count++;
    } while (num != randNum && count<20);
    if (count == 1) {
    System.out.println("你太有才了");

    }
    if (2 <= count && count >= 6){
    System.out.println("这么快就猜出来了,很聪明嘛");
    }
    if (20>count&&count >= 7) {
    System.out.println("小同志,还需努力呀");
    }
    if(count>20){
    System.out.println("次数用尽");
    }
    }
    } else {
    System.out.println("登录游戏失败,退出游戏");

    }
    System.out.println("——游戏结束——");
    }
    }
  • 相关阅读:
    Pascal's Triangle II
    Pascal's Triangle
    Path Sum II
    Path Sum
    plusOne
    Divide Two Integers
    64. ZigZag Conversion
    63. Swap Nodes in Pairs && Rotate List && Remove Nth Node From End of List
    62. Divide Two Integers
    61. Unique Paths && Unique Paths II
  • 原文地址:https://www.cnblogs.com/lyy2993945268/p/11959960.html
Copyright © 2011-2022 走看看