Hello! | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 3

Hello!

please help me with the task with the name "getting user input", I didn't understand. I read everything, but still don't know what to insert. thank you

4th Apr 2017, 5:59 AM
Diana
3 Answers
+ 9
This module is talking about The Scanner class.This class is used to get input from the user,example you can ask someone their name, and then store it.First off, since the class is predefined inside the java.util package, you have to import it.So at the start of your code write:- import java.util.Scanner //Please note capital 'S' Now you need to create an object of this class,since to use a class' method,you need an object.Create one as follows:- Scanner sc=new Scanner(System.in); Here sc is a variable name,of an object of Scanner class.new is used to create objects.Scanner(System.in) is calling the constructor of Scanner class.System.in means input. Finally to store an info,you will need to decide the datatype of it.If its a string type:- String name=sc.next(); Here an input would be stored in name variable. sc.next() means next() method of sc object is called. Similarly,For integers, int z=sc.nextInt(); for doubles:- double m=sc.nextDouble(); etc. NOTE:- If your new to object oriented programming, I hardly doubt you can understand it NOW.It will take time,carry on with next courses,you will automatically get it :-)
4th Apr 2017, 6:18 AM
Meharban Singh
Meharban Singh - avatar
+ 5
Anytime @Diana
4th Apr 2017, 10:38 AM
Meharban Singh
Meharban Singh - avatar
+ 3
thank you for this answer! !! I new in programming, I start learn it with this good app))
4th Apr 2017, 7:25 AM
Diana