+ 2
How to scan multiple string in a single line?
For example there are 2 strings. First one is cat secone one is move. Then the input of the code should be cat move.
3 Respuestas
+ 3
Version 4:
Scanner scan = new Scanner(System.in);
//.next() reads a String until a white space //it reads not the full line
String a = scan.next();
String b = scan.next();
System.out.println(a + " " + b);
input: cat move
output: cat move
+ 5
Hope this helps
https://code.sololearn.com/ckJ040X9d1hx/?ref=app
+ 1
Version 1:
Scanner scan = new Scanner(System.in);
//read just the line
String str = scan.nextLine();
System.out.println(str);
input: cat move
output: cat move
Version 2:
Scanner scan = new Scanner(System.in);
String a = scan.nextLine();
String b = scan.nextLine();
System.out.println(a + " " + b);
input: cat
move
output: cat move
Version 3:
Scanner scan = new Scanner(System.in);
//scan.hasNext() returns true if there is a next Line
while(scan.hasNext()){
String str = scan.nextLine();
System.out.print(str + " ");
}
input: cat
moves
along
the road
output: cat moves along the road