+ 1

How to get multiple input with scanner?

my code is not running. i want to have multiple input with scanner https://code.sololearn.com/cA2YLjShIljG/?ref=app

3rd Aug 2017, 1:41 PM
Shobh
Shobh - avatar
7 Respuestas
+ 5
class MyClass { public static void main(String[ ] args) { Scanner a = new Scanner(System.in); //Scanner b = new Scanner(System.in); System.out.println (a.nextLine()); System.out.println(a.nextLine()); } } Then type this way: a b
3rd Aug 2017, 1:54 PM
Corey
Corey - avatar
+ 4
You can also use for loop to let user input many times, but seems can't implement in Sololearn. Or request user input a comma-sperated line, then split the input by String.split(",").
3rd Aug 2017, 1:59 PM
Corey
Corey - avatar
+ 3
first off all only one scanner is enough to get input of multiple variables and yea u didnt even declare the variables do something like Scanner sc = new Scanner(System.in); int a,b; a=sc.nextInt(); b=sc.nextInt(); System.out.println (b); System.out.println(a);
3rd Aug 2017, 1:53 PM
Suhail Pappu
Suhail Pappu - avatar
+ 2
@Shobh If you want to use a variable, then use one 😜 String input = myVar.nextLine();
3rd Aug 2017, 3:55 PM
Rrestoring faith
Rrestoring faith - avatar
+ 1
but why we are not declaring variable in single input by scanner https://code.sololearn.com/c1o8Sih2kiRK/?ref=app
3rd Aug 2017, 2:01 PM
Shobh
Shobh - avatar
+ 1
import java.util.Scanner; /*Copy this. and on input screen Enter a "string word" and on a seprate line enter a "int number" and run. This just shows you how to use words and numbers with scanner */ class MyClass { public static void main(String[ ] args) { Scanner z = new Scanner(System.in); String a = z.nextLine(); int b = z.nextInt(); System.out.println (a); System.out.println(b); } }
3rd Aug 2017, 2:10 PM
D_Stark
D_Stark - avatar
0
How to separate two integers with a delimiter... Like this 2:3.. And this should be done in 3 lines!!
26th Jul 2020, 7:17 AM
Vishwanath
Vishwanath - avatar