java - BufferedReader.readLine is not working -
this question has reply here:
how compare strings in java? 23 answersmy programme kind of gets stuck after readline call, if statements don't work. doing wrong? #java-first-timer
import java.io.inputstreamreader; import java.io.bufferedreader; import java.io.ioexception; public class nums { public static void main(string[] args) throws ioexception { bufferedreader br = new bufferedreader(new inputstreamreader(system.in)); system.out.println("number mania!!!"); system.out.println("pick favourite number 1 5"); string favnum = br.readline(); if (favnum=="3"){ system.out.println("your favourite number three!"); } else{ system.out.println("hi!"); } } }
use favnum.equals("3")
instead of favnum == "3"
. should never utilize ==
compare objects; utilize .equals
instead. (there few rare exceptions, won't need worry them until larn fair bit more java.)
java
No comments:
Post a Comment