Language: Java.
Aim: Boolean Array gridA[] should become true on whatever index is read from input (i.e. if input is "init_start 2 4 5 init_end" then gridA[] indexes 2,4 and 5 should become true). That much I managed to get working but I have two problems:
input: init_start int int int int int (...) int init_end for example: init_start 2 6 12 init_end
Problems: any integer from input that exceeds the value of (instance variable) int L (which determines the index-length of the array) should be ignored, to prevent integers from outside the domain of Array gridA[] from having influence. Using if(scanner.nextInt != L){} didn't seem to work.
I also need this method, or the body of the method to start when input begins with "init_start" and stop when input ends with "init_end". How do write code so that it can read both String and integers from the same input?
I meant to do this using if(scanner.Next=="init_start") followed by a = scanner.NextInt; which, as I suspected, didn't work.
Attempts at solving: After googling I tried putting String initialInputStart in a Scanner: localScanner(initialInputStart); but I failed to get that working. Other information I found suggested I'd close and reopen the scanner but I need the information to be read from a single line of input so I doubt that will help.
code:
java.util.Arrays.fill(gridA,false);
java.util.Arrays.fill(gridB,false);
String initialInput;
String initialInputStart;
int a;
int i;//only for testing
i = 0;//only for testing
System.out.println("type integers"); //only for testing
while( scanner.hasNextInt() && i<5){ //I can't find a way to make loop stop without missing input so I'm using i temporarily
a = scanner.nextInt();
gridA[a] = true;
System.out.print(a);
System.out.print(gridA[a]+" ");
i++;
}//end while
scanner.nextInt()gets the int, but wont proceed to the next line of your console try:int yourVariable = Integer.parseInt(scanner.nextLine())