+ 1

How to get input from the keyboard to the variable

10th Mar 2017, 11:34 AM
Anandhakrishnan K
Anandhakrishnan K - avatar
7 Respuestas
+ 3
import java.util.Scanner; public class Anything{ public static void main(String[] args){ Scanner anyOtherThing = new Scanner(System.in); String input=anyOtherThing.next(); }} Hence input has required input (LOL) ALSO, if you want an integer input, replace last line by, int input=anyOtherName.nextInt(); if its double then nextDouble();. etc...
10th Mar 2017, 11:44 AM
Meharban Singh
Meharban Singh - avatar
+ 1
use scanner or bufferReader
10th Mar 2017, 11:41 AM
Meharban Singh
Meharban Singh - avatar
0
When using this syntax it throws an error that scanner cannot be resolved to a type
10th Mar 2017, 1:04 PM
Anandhakrishnan K
Anandhakrishnan K - avatar
0
change next() to nextLine();
10th Mar 2017, 1:15 PM
Meharban Singh
Meharban Singh - avatar
0
still the same error appears
10th Mar 2017, 1:19 PM
Anandhakrishnan K
Anandhakrishnan K - avatar
0
make sure, you have imported Scanner class.
10th Mar 2017, 1:38 PM
Meharban Singh
Meharban Singh - avatar
0
Its working absolutely fine by me. Please re-do it in Soloearn's code Playground and save it ,make it public and msg me. I will check it.
10th Mar 2017, 1:45 PM
Meharban Singh
Meharban Singh - avatar