I am making a program where the computer guesses your number. And it has to guess a random num. But it guess negative numbers and numbers over 100, in addtion it does not pick a num in a range like if the person says the computer it too high than the program will generate a number hight the than the original guess.
i used the random range method from here: A
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();
while(a.equalsIgnoreCase("no"))
{
System.out.println("Was i too high or low?");
b = scan.nextLine();
if(b.equalsIgnoreCase("high"))
{
int ran1 = ran - (int)(Math.random()*100);
System.out.println("Is it " +ran1 +" humm?");
}
if(b.equalsIgnoreCase("low"))
{
int ran1 = ran + (int)(Math.random()*100);
System.out.println("Is it " +ran1 +" humm?");
}
}
}
}
}