Java数字猜谜游戏使用循环

时间:2019-11-20 22:00:00

标签: drjava

/**
 * November 19 2019
 * Description: Computer selects a number from 1 - 1000 if you are unable to 
 * guess the number in 10 tries you lose, but have the opportunity to play again
 * and get a number and a next 10 guesses to win.
 */
import java.util.Scanner;
import java.util.Random;

public class A3Major {


  public static void main(String[] args) { 

    Scanner scan = new Scanner(System.in);
    Scanner keyboard = new Scanner(System.in); 
    Random numGenerator = new Random();
    int randNum;
    int guess;
    int tries = 0;
    boolean win = false;

    System.out.println("NUMBER GUESSING GAME"); 
    System.out.println("Made by Anon");
    System.out.println("Instructions and Rules:");
    System.out.println("1. Pick a number between 1 - 1000");
    System.out.println("2. You have 10 tries to guess the number" );
    System.out.println("3. If number is too high, system will say lower if too low system will say higher");
    System.out.println("4. If number is not between 1 - 1000 guess is invalid" );

    While (win == false) {
    System.out.println("Guess a number between 1 - 1000");
    System.out.println("Guess number is 14");  
    guess = input.nextInt();
    tries++;

    if(guess == number){
     System.out.println("Lower");
    }

   else if(guess > number){
     System.out.println("Higher");
    }

    else if(guess < number){
      System.out.println("You Win");
    }
    else {
      System.out.println("Invalid");
    }

    }


      String input = scan.nextLine();         

    if (input.equalsIgnoreCase("14")) {
      System.out.println("You win");
    }

    else {
      System.out.println("Higher");
    }

    for (int i=1; i <= 100 ; i++) {
      randNum = numGenerator.nextInt(10) + 1;
      System.out.print(randNum + ", ");
    }
    System.out.println();
  }
}

我主要的问题是,如果我不是一个有经验的编码员,到目前为止看起来如何,需要更改什么?应该添加什么?不需要什么?一般而言,我那里的代码有什么问题。另外,我将接受您可能必须分享的任何建设性批评,因为我很可能会在这个过去对我有帮助的网站上提出更多问题。

0 个答案:

没有答案