In this code, I am prompting the user to pick a number from 1-1000 and having the user keep it in his/her head.
Then, in 10 tries or less I am trying to have the computer guess the user's number.
This is what I have so far...
import java.util.*;
public class Guessnumber{
public static void main(String[] args){
System.out.println();
System.out.println("Think of a number from 1-1000 and do not tell me,");
System.out.println("I will try to guess the number.");
System.out.println();
int g=500;
int numguesses=0;
System.out.println("For too low enter 1.");
System.out.println("For too high enter -1.");
System.out.println("For correct enter 0.");
System.out.println();
System.out.println(g);
int guessparam=parameter(g);
}
public static int parameter(int g){
Scanner console=new Scanner(System.in);
int hint=console.nextInt();
do{
System.out.println("Is this too high, too low, or correct?");
System.out.println(g);
if(hint==1){
g=(g/2)+g;
return g;
}else if(hint==-1){
g=g/2;
return g;
}else
g=g;
return g;
} while (hint!=0);
}
}
I know the math is wrong, but when I run it the calculations aren't even performed. I am new to java and any guidance in the write direction would be much appreciated.