+ 1
What is the way to get two different string inputs in Java,using Scanner.
Scanner in Java
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();
+ 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());