Scanner in for loop | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Scanner in for loop

What is the problem? import java.util.Scanner; public class Program { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int num = sc.nextInt(); for(int i=0; i<num; i++){ String name = sc.nextLine(); String[] str = name.split(" "); System.out.println(str[0]); System.out.println(str[1]); } } }

23rd Mar 2020, 7:09 PM
hamid
hamid - avatar
2 Answers
+ 2
Could you please tell us that what are you trying to achieve with this piece of code. What is the input like and what is the output you are expecting out of it?
23rd Mar 2020, 7:15 PM
Avinesh
Avinesh - avatar
0
for exemple u can insert 3 as first input, and a string (name family) as second one.
23rd Mar 2020, 7:22 PM
hamid
hamid - avatar