int n,i;
Scanner sc = new Scanner(System.in);
n=sc.nextInt();
String[] str = new String[n];
String s = null;
for(i=0;i<n;i++){
s = sc.nextLine();
str[i] = s;
}
System.out.println(i);
for(i=0;i<n;i++){
System.out.println(str[i]);
}
sample input & output
4 a s d
4
a s d
In the above case I can't get or print str[0]