-2

i am mking a program where the computer guesses your number. and it has to guess a random num. but how do i make the random line be lower or higher num than the perviously num guessed?

package compguse;
import java.util.*;

public class Compguse {


public static void main(String[] args) {
    Scanner scan = new Scanner (System.in);
    String a;
    String b;      
    String c;
    String ans;
    String d;        
    int input =1;
    System.out.println("do u have your number?");
    a = scan.nextLine();
    while (a.equalsIgnoreCase("yes"))
    {
    int ran = (int) Math.floor(Math.random()*100)+1;
        System.out.println(" is" +ran +" your num?");  
        a = scan.nextLine();
        if(a.equalsIgnoreCase("no"))
        {
            System.out.println("Was i too high or low?");
            b = scan.nextLine();
            if(b.equalsIgnoreCase("high"))
            {
            int ran1 = (int) Math.floor(Math.random() < (int) ran);

            }    
        }       
    }
}
Bhagyesh
  • 700
  • 10
  • 31

1 Answers1

1

Just make a while loop which implements this pseudocode:

For example if you want it to be less than the guess:

while random is greater than guess random = new random number

Alex
  • 627
  • 3
  • 12
  • 32