title: Scanner's function .nextLine() wont accept input inside a for loop?
body: <p>I need to have the user input a size of the array in the variable <code>n</code> and then create a single dimension array of Strings and have it filled with sentences. I also need to make sure that each sentence ends with a full stop (a <code>.</code> ). so here's what I have:</p>
  
  <pre><code>import java.util.*;
  class encryption{
          void main(){
                  Scanner sc=new Scanner(System.in);
                  System.out.println("Enter the number of sentences to be encrypted");
                  int n=sc.nextInt();
                  String[] a=new String[n];
                  System.out.println("Enter the sentences");
  
                  for(int i=0; i&lt;n; i++){
                      a[i]=sc.nextLine();
                      while(a[i].charAt(a[i].length()-1)!='.'){
                          a[i]=sc.nextLine();                                                
                      }
                      if(i%2==0){
                          a[i]=rev(a[i]);
                      }
                      else{
                          a[i]=frwd(a[i]);
                      }
  
                  }
                  for(int i=0; i&lt;n; i++){
                      System.out.println(a[i]);
                  }
              }
  </code></pre>
  
  <p>After the inputs, I will work on the Strings using the functions <code>rev(...)</code> and <code>frwd(...)</code>, and then print the changed strings. </p>
  
  <p>It compiles fine, however upon execution, the first line in the first <code>for</code> loop <code>a[i]=sc.nextLine();</code> doesn't seem work. It gives me a straight  <code>indexOutOfBounds</code> error meaning it goes straight onto the <code>while</code> loop.</p>
  
  <p>How can I make it accept input there?</p>