+ 1

Can anyone please help me with the usage of Scanner ,next line and others?

Actually the format given seems to be very different from what I have learnt till now. I request you all to help me to crack this topic and understand it more correctly.

1st Jan 2018, 5:25 AM
Shikhar
Shikhar - avatar
4 Answers
+ 1
To take input, you first need a Scanner object. To make one, simply... make one like the following: Scanner sc = new Scanner(System.in); Now, with this object, you can take different types of input. You can take ints, doubles, Strings, chars, and more. To take an int and store in an a variable called "input," do this: int input = sc.nextInt(); For other types, like double and String, use nextDouble() and nextLine(), respectively. Make sure to change the type of the "input" variable to double and String as well. If you have any more questions, please ask.
1st Jan 2018, 5:29 AM
LunarCoffee
LunarCoffee - avatar
+ 1
thanks buddy
1st Jan 2018, 5:35 AM
Shikhar
Shikhar - avatar
+ 1
@Sheetal looks fine
9th Jan 2018, 5:25 PM
LunarCoffee
LunarCoffee - avatar
0
can anyone tell me what's wrong in this code? import java.util.Scanner; class MyClass { public static void main(String[ ] args) { Scanner myVar = new Scanner(System.in); System.out.println(myVar.nextLine()); } }
9th Jan 2018, 10:28 AM
Sheetal Thombre
Sheetal Thombre - avatar