After trying to test this Bufferered Reader
import java.io.*;
public class Test {
public static void main(String[] args) throws IOException{
BufferedReader Br = new BufferedReader(new InputStreamReader(System.in));
if (Br.readLine() == "one") print1();
if (Br.readLine() == "two") print2();
}
public static void print1(){
System.out.print("1");
}
public static void print2(){
System.out.print("2");
}
}
Nothing I can type in will get it to print. If I change the first "if" statement to
if (Br.readLine().startsWith("one") print1();
it will print "1" if I type in "one". Why does this happen?
==. Use.equals()instead.