0
Why sc.nextLine(); is used in this code? (Java)
https://code.sololearn.com/ca21A17A10a1/?ref=app 1) What's the usage of sc.nextLine(); in this code? 2) Why the value of String is not printing when I remove sc.nextLine(); ? Please enlighten me 🙏
6 Respuestas
+ 3
Read this lesson and the associated comments :
https://www.sololearn.com/learn/Java/2220/?ref=app
+ 3
Rabeeh Your code has errors .
You need to import the Scanner class like import java.util.Scanner;
And there's no need for writing sc.nextLine() twice .
String s = sc.nextLine(); is used to input or read a line of text ....
+ 3
Rabeeh So i think your real Question on nextLine has been solved .Now about the new Question Ya idk as u said check the version .
+ 2
Rabeeh
Do you know how to assign value to a variable. If you know then this question should not come in your mind.
You asked if we have String s = sc.nextLine() then why sc.nextLine()
If you are cleared about concepts then you should know that sc.nextLine() returns String so here we assigned sc.nextLine() to a String variable s.
String s = sc.nextLine();
Problem is that you have just completed the lessons but didn't understand the concepts.
0
I already completed this lesson but my question is why the sc.nextLine(); here because we already have String s=sc.nextLine(); so what's the role of sc.nextLine(); ?
0
Alphin K Sajan I see I didn't run the code in Sololearn and you're right when I import scanner it's working here but it's still showing error in IntelliJ ide. Is this because of Java version?