0
  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]

  • How can you tell that you're not getting str[0]? May I suggest that you print the str element with System.out.println("-" + str[i] + "-"); This will allow you to see strings with no length and strings with white space on them. – NomadMaker Jun 08 '20 at 03:50

0 Answers0