sphinx2001

Угадай число - исправлено

Sep 24th, 2019
222
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.24 KB | None | 0 0
  1. import java.util.Scanner;
  2. import java.util.Random;
  3. public class SuggestNumber{
  4.     public static void main(String[] argv){
  5.         Scanner sc = new Scanner(System.in);
  6.         Random r = new Random();
  7.         System.out.println("Game suggest number");
  8.         int maxTry = 8;
  9.         int count = 0;
  10.         System.out.println("Please guess the number between 1 - 100");
  11.         int num = r.nextInt(100);
  12.         int minNum = 1;
  13.         int maxNum = 100;
  14.         String answer = "";
  15.         String a = "123";
  16.  
  17.         while(true){
  18.             //count = count + 1;
  19.             count++;
  20.             System.out.println("It is " + num + "? (> < =)");
  21.             answer = sc.nextLine();
  22.             if(answer.equals(">")){
  23.                 minNum = num;
  24.             }else if(answer.equals("<")){
  25.                 maxNum = num;
  26.             }else if(answer.equals("=")){
  27.                 System.out.println("Computer won in " + count + " attemps!");
  28.                 break;
  29.             }else{
  30.                 System.out.println(count);
  31.             }
  32.             if(count >= maxTry){
  33.                 System.out.println("User won!");
  34.                 break;
  35.             }
  36.             num = minNum + r.nextInt(maxNum-minNum);
  37.         }
  38.     }
  39. }
Add Comment
Please, Sign In to add comment