0
User input String in Java !!!
Can't I get string input using this method..? //scan is my Scanner name String sentence = scan.nextLine (); I tried it but my program didn't asked me to give any input... What is problem with this one.. ? Can anyone tell me in details please :(
27 Réponses
+ 9
1. Did you define your scan variable like this?
Scanner scan = new Scanner (System.in);
2. Does your code throw an error? If so, what is the error message?
+ 9
Could you publish your code at the playground and add a link to it here?
+ 2
It's not reserved I see, that's my fault. The Sololearn IDE usually indicates reserved keywords in blue but I see now it only made it blue because it started with a capital letter. My apologies, I'll subtract my comment
+ 2
@Mazharual here's a workable version of your code. When you run it and it requests input then separate your inputs with a space to enter multiple inputs (e.g 1.0 2.0 Hello)
https://code.sololearn.com/c09ITW62EVgm/?ref=app
+ 2
I just made your variables lowercase and commented out your package at the top of your code.
+ 2
It was confusing for me too @Mazharul but I see now that nothing was really wrong with your variable names. The only problem your code had was that package you included. Why I got confused was because the variable names were in blue.
+ 2
No, you use the package keyword to make a package of the code you're creating and then save it as a java file. Then in your main code you can import that package with the import keyword.
Example (Java):
import java.util.* //imports all classes of the util package.
//Show when you must not use the package keyword with your main code
+ 1
I read that you shouldn't use the same scanner for both Strings and numbers. I don't know that that's the problem, but I would try a second scanner for strings
+ 1
Ohh I see.. Thanks a lot brother for your kind information :)
+ 1
https://code.sololearn.com/ce4JLgF9DfSw/?ref=app
use this link bro
+ 1
thanks bro@ gavin
+ 1
Hi Mazaharul,
both are used to read string alone.
if u want to read int then use nextInt() ,nextFloat() for float and nextDouble() for double.
+ 1
then use nextLine() bro
+ 1
oh ok
0
Yes.. Defined like that but there is no error message.. while I run it just execute the program
0
@Tashi N I'm publishing then will add the link here.. Thanks for your interest :)
0
Joker yes I did.. my scanner taking int,double,float but not string in sequenc
0
My code link.. :(
https://code.sololearn.com/cymgKvE1p71I/?ref=app
0
Brother Gavin, I tried it in my PC with NetBeans IDE :(