io - Java Standard System Input and Buffered Reader -


after trying test 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 can type in print. if change first "if" statement to

if (br.readline().startswith("one") print1(); 

it print "1" if type in "one". why happen?

when comparing strings should change == .equals() due fact .equals() compares contents of strings each other or used compare objects. == checks reference equality or used compare primitives. changed code below:

if (br.readline().equals("one")) print1(); if (br.readline().equals("two")) print2(); 

Comments

Popular posts from this blog

java - WrongTypeOfReturnValue exception thrown when unit testing using mockito -

php - Magento - Deleted Base url key -

android - How to disable Button if EditText is empty ? -