What I am trying to do is, get input string from user. Add it into arraylist since i have to play with characters later. But first i want to print contents of ArrayList in order to check what is exactly in their. Here is my code
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
List <String> Vowels = new ArrayList<String>();
System.out.println("What is your string? ");
String abc = sc.nextLine();
int n = abc.length();
for(int i=0; i <= n-1 ; i++)
{
Vowels.add(sc.nextLine());
}
for(int j=0; j< Vowels.size();j++)
System.out.println(Vowels.get(j));
}
It is not printing anything or not showing up any error. Your help will be highly appreciated.
sc.nextLine()in your for loop is going to block waiting for user input. Your logic is strange as well I think. If you enter the word "wally" then the for loop is going to require you to enter 5 more lines. Is this right?