+ 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

29th Jun 2019, 2:23 PM
Just a coder
Just a coder - avatar
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!"); } }
29th Jun 2019, 2:37 PM
Daljeet Singh
Daljeet Singh - avatar
+ 1
Thank you, Daljeet Singh!
29th Jun 2019, 2:49 PM
Just a coder
Just a coder - avatar
+ 1
I would like yo know why the library útil.scanner what is used for?
29th Jun 2019, 4:03 PM
sandra ojeda
+ 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
30th Jun 2019, 8:17 AM
Daljeet Singh
Daljeet Singh - avatar