sugarbabee
09-30-2008, 05:28 PM
Hi there, I'm currently trying to get this code to work so that each word of a user's input will be stored in an array, which I do using a while(scanner.hasNext()) loop, and then I want to be able to loop through the resulting array and print output its contents using system.out.println(). The problem is that nothing seems to happen once the loop has finished, even if I try to print some random message like "adadfh" after, it doesn't output.
Does anyone know why this is happening? Here is the loop:
String[] array = new String[10];
counter = 0;
Scanner s = new Scanner(System.in);
while(s.hasNext()) {
String i = s.next();
array[counter] = i;
counter ++;
}
System.out.println("This won't print");
Any help would be greatly appreciated, maybe its something in the Scanner that's preventing the code after it from executing?
Thanks in advance!
Does anyone know why this is happening? Here is the loop:
String[] array = new String[10];
counter = 0;
Scanner s = new Scanner(System.in);
while(s.hasNext()) {
String i = s.next();
array[counter] = i;
counter ++;
}
System.out.println("This won't print");
Any help would be greatly appreciated, maybe its something in the Scanner that's preventing the code after it from executing?
Thanks in advance!