I'm trying to scan an integer and run a loop to scan strings until that integer. But this code skips the first string...
import java.util.ArrayList;
import java.util.Scanner;
public class A1 {
public static void main(String[] args) {
ArrayList <String> A = new ArrayList<String>();
Scanner sc = new Scanner(System.in);
System.out.println("How many strings to add:");
int a = sc.nextInt();
for(int i=0; i<a; i++)
{
System.out.printf("Enter %dth string:\n", i+1);
String s = sc.nextLine();
A.add(s);
}
for(int i=0; i<A.size(); i++)
{
System.out.println(A.get(i));
}
}
}
Any solution?