+ 13

My code do not give out what it should be. It says NoSuchElementException. What does that mean ?

https://code.sololearn.com/cHqbOpYNx4Zr/?ref=app

1st Apr 2018, 11:53 PM
Jasmin
Jasmin - avatar
11 Answers
+ 14
Codes in the Code Playground do not run in realtime. Your code asks for 2 inputs, so you have to put both values in the input box, like this: Jasmin yes
2nd Apr 2018, 12:00 AM
Tamra
Tamra - avatar
+ 7
Hey Jasmin In this case it means that you are not giving it two pieces of information required for the two inputs, when I tried it with my name and the string "yes" it worked. If you skip the input you get the mentioned error. However, I should also let you know that you won't get the expected output when you enter the string "yes" as when you are comparing strings you should use the .equals () method as == compares the addresses and not the content of the strings thus it will mostly default to false. Hope it helped!
2nd Apr 2018, 12:04 AM
Tarantino
Tarantino - avatar
+ 6
Jasmin ā†© Yes ā–¶
2nd Apr 2018, 12:14 AM
BroFar
BroFar - avatar
+ 4
Try this Robert Brown Farley (brofarops) , your inputs are: Robert yes https://code.sololearn.com/csdC7KduuHLH/?ref=app Then try Jasmin's with the same input.
2nd Apr 2018, 10:25 PM
Tarantino
Tarantino - avatar
+ 4
ok - i don't know why it didn't work initially when i changed it but yup it does work in your example and hers too - Wow! must have been a system glitch -
2nd Apr 2018, 10:30 PM
BroFar
BroFar - avatar
+ 3
Hi, replace the == sign with below to get the exact results. if (like.equals("yes"))
2nd Apr 2018, 9:09 PM
Nabeel
Nabeel - avatar
+ 3
jasmin. i noticed an error in ur code at line 14, that might be the reason your code doesn't work. I think to read a string value input using scanner class, the syntax should be String Like=Scanner_name.nextLine(); https://code.sololearn.com/cL5MApgANnuD/?ref=app
3rd Apr 2018, 10:13 AM
Baines
Baines - avatar
+ 2
Because you have used twice scanner.next(); Without checking if thereā€™s an input.
2nd Apr 2018, 12:02 AM
GeekDandi
GeekDandi - avatar
5th Apr 2018, 9:49 PM
Parmar Jayeshkumar L.
Parmar Jayeshkumar  L. - avatar
0
like others may have indicated, need to account for having only 1 line. If you put in more that 1 line you don't get that exception. https://www.tutorialspoint.com/java/util/scanner_next.htm
10th Apr 2018, 7:21 PM
Mike Edmison
Mike Edmison - avatar
- 1
you a incredibly amazing jazmin.... keep it up
12th Jun 2018, 6:34 AM
Abdihakim issack
Abdihakim issack - avatar