+ 1
Java print user imput
How can I ask someone a question, for example what's their name, using the user imput, and then show it with println like a sentence (something like "Name is such a beautiful name!”). I tried to do it, but I couldn't. https://code.sololearn.com/c8uxL998pU50/?ref=app
4 ответов
+ 2
import java.util.Scanner;
// you have to import the Scanner class to use the Scanner object
class MyClass {
public static void main(String[ ] args) {
Scanner sc = new Scanner(System.in);
System.out.println("What is your name?");
String name = sc.nextLine();
System.out.println(name + " " + "is such a beautiful name!");
}
}
+ 1
Thank you, Daljeet Singh!
+ 1
I would like yo know why the library útil.scanner what is used for?
+ 1
Just a coder you need to change line 4 in your code like this:
Scanner sc = new Scanner(System.in);
To have a more insight use these links @ sl
https://www.sololearn.com/learn/Java/2220/?ref=app
And sandra ojeda
https://www.geeksforgeeks.org/scanner-class-in-java/
This resource link will provide you lots of study materials (links and ebooks etc..
https://www.sololearn.com/Discuss/580291/?ref=app