Small problem

This is quite simple but i don't know hot to do it! So help will be appreciated.

I have the following code:

String input ="";

BufferedReader ir =new BufferedReader(new InputStreamReader(System.in));

input = ir.readLine();

if(input.equals("go"){

System.out.println("Typed go");

method1(input);

}

if(input.equals("here")){

System.out.println("Typed test2");

Method2(input);

}

So this code SHOULD wait for an input from the command line, if a if statements is satisfied then it should open a method which should take in a DIFFERENT input. This code doesn't do that.

So i don't want the first input typed to be used as the arguments for the methods. But this is what happens.

Any suggestions on how i can overcome this? thanks in advance.

[1198 byte] By [abshirf2a] at [2007-11-26 20:49:18]
# 1

Perhaps:

BufferedReader ir = new BufferedReader(new InputStreamReader(System.in));

String input = ir.readLine();

if(input.equals("go"){

System.out.println("Typed go");

input = ir.readLine();

method1(input);

} else if(input.equals("here")){

System.out.println("Typed test2");

input = ir.readLine();

method2(input);

}

or pass the BufferedReader to method1 and method2 and let them do their own reading.

DrLaszloJamfa at 2007-7-10 2:13:06 > top of Java-index,Java Essentials,Java Programming...
# 2
This code:ir.readLine(); is what reads input from the console. You only call it once, so what makes you think you'll read a second line of input? If you want to read more in the if statement, then you need to use that line again.
hunter9000a at 2007-7-10 2:13:06 > top of Java-index,Java Essentials,Java Programming...
# 3
Oh! Your right. Thank you very much.This actually ironed out other problems i had. Thank You!
abshirf2a at 2007-7-10 2:13:06 > top of Java-index,Java Essentials,Java Programming...