+ 1

What is the way to get two different string inputs in Java,using Scanner.

Scanner in Java

28th May 2019, 11:29 AM
Joyel Dsilva
Joyel Dsilva - avatar
2 Answers
+ 3
String a = Scanner.next(); //the first string until a white space String b = Scanner.nextLine(); //the whole line E.g. you want a name and an adress from a user: Scanner scan = new Scanner(System.in); String name = scan.nextLine(); String adress = scan.nextLine(); e.g. you want two words from a user: String word1 = scan.next(); String word2 = scan.next();
28th May 2019, 2:08 PM
Denise Roßberg
Denise Roßberg - avatar
+ 1
Here is two different ways Scanner scan = new Scanner(System.in); // Example 1 String text = scan.nextLine(); System.out.println(text); // Example 2 System.out.println(scan.nextLine());
28th May 2019, 12:01 PM
JavaBobbo
JavaBobbo - avatar