I am trying to create a rudimentary number guessing program with java, and it is not working out. I think i have some useless stuff in there, but whatever:
import java.util.Random;
import java.io.* ;
public final class Number_guesser {
public static final void main(String... aArgs){
InputStreamReader istream = new InputStreamReader(System.in) ;
BufferedReader bufRead = new BufferedReader(istream) ;
System.out.println("Welcome to the 'pick a number game'.");
System.out.println("Press the 'Enter' or 'Return' key to continue after everything I say...");
Getch();
System.out.println("Think of a number from one to four...");
Getch();
System.out.println("Did you think of it?");
Getch();
System.out.println("Ok, good...");
int START = 1;
int END = 4;
Random random = new Random();
for (int idx = 1; idx <= 1; ++idx){
showRandomInteger(START, END, random);
}
}
private static void showRandomInteger(int aStart, int aEnd, Random aRandom){
if ( aStart > aEnd ) {
throw new IllegalArgumentException("Start cannot exceed End.");
}
long range = (long)aEnd - (long)aStart + 1;
long fraction = (long)(range * aRandom.nextDouble());
int randomNumber = (int)(fraction + aStart);
log("Was your number " + randomNumber + "?");
}
private static void log(String aMessage){
System.out.println(aMessage);
}
boolean go = true;
While (go){
try {
System.out.println("Was I correct:");
String word = bufRead.readLine();
int word = Integer.parseInt(word);
}
catch (IOException err) {
System.out.println("Error reading line");
}
catch(NumberFormatException err) {
System.out.println("Error Converting Number");
}
if (word = "no"){
System.out.println("Oh well, better luck next time");
Getch();
}
if (word = "yes"){
System.out.println("I knew it!");
}
else{
System.out.println("Please say 'yes' or 'no' in lowercase letters");
}
System.out.println("would you like to play again?");
char[] userInput = new char[1];
int a = System.in.read(userInput);
if( userInput[0] != "yes" ){
go = false;
}
}
}
I got the following errors and I don't know what the H∑|| they mean:
Number_guesser.java:46: invalid method declaration; return type required
While (go){
^
Number_guesser.java:46: <identifier> expected
While (go){
^