import java.util.*;
public class Main {
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
// sc.nextLine();
int num=0,i=0,fnum=0;
while(t-- >= 0){
String str = sc.nextLine(); //10th line
String sarr[] = str.split("");
for(int j=0;j<str.length();j++){
System.out.print(sarr[j]);
}
System.out.println();
}
}
}
Input:
2
101
111111
Output:
101
111111
Why is the first line empty?(This was tested on a non interactive compiler) Also, i read that in java after taking integer input in Java , we have to use sc.nextLine(); before taking the immediate next String input.But when I use that in above program it gives me an error, why?
Exception in thread "main" java.util.NoSuchElementException: No line found
at java.util.Scanner.nextLine(Scanner.java:1540)
at Main.main(Main.java:10)