java - Using answer in if -


java new me, , ran problem. code:

string answer;  system.out.println("choose day"); answer = tastatur.nextline();   if(svar.equals("saturday"))   system.out.println("saturday"); 

basically, want use answer in if statement. not work, , don't understand why. help?

you looking @ wrong variable.

if( answer.equals("saturday") ){    system.out.println("saturday") }   

what's logic?
reading user entering answer variable. in code checking svar variable while should checking answer variable. if indeed user entered saturday, print on screen. else, not.

equalsignorecase() better method use because saturday , saturday different in sense 1 has capitalized s , other not. equals() treat them different.

you have said java new you. hope initializing tastatur variable as:

bufferedreader tastatur = new bufferedreader(new inputstreamreader(system.in));   

and using import java.io.* in program.


as aside, please read official tutorials provided java. resource. ask questions on stackoverflow when have run out of luck while looking answers yourself. said, welcome stackoverflow mercilessly close questions if not meet our standards or contain spam.


Comments

Popular posts from this blog

Python Kivy ListView: How to delete selected ListItemButton? -

asp.net mvc 4 - A specified Include path is not valid. The EntityType '' does not declare a navigation property with the name '' -