I am working on a program that requires me to simulate an operating system linker using text input from a file that is scanned in from the command line. There are multiple problems that I am having with this assignment, however, the first of which is why my method of isolating certain elements of input is only returning some of the elements that match the criteria and not all. What the following code is trying to do is to traverse the input while checking to see if the input is equal to a string. It then advances the input and checks to see if the next input is an int, if it is, then it checks to see if its greater than 10 and assigns it to a value and then prints this value with each iteration of the while loop. So my question is why isn't doing what I want, i.e. printing all the input that matches the criteria instead of just some of it. If anybody can help me with this, perhaps they could help me with some of my other problems.

int address;
        input=input.reset();
        while (input.hasNext()) {
 
            if ((input.next()).equalsIgnoreCase("A")) {
                if (input.hasNextInt()) {
                address = input.nextInt();
                if (address > 10) {
                System.out.println(address + " : " + address);
                }
                if (input.hasNext()) {
                    input.next();
                }
            }
            }
            else if (input.hasNext()) {
                input.next();
            }
        }

Sample Input:

1 xy 2
2 z xy
5 R 1004  I 5678  E 2000  R 8002  E 7001
0
1 z
6 R 8001  E 1000  E 1000  E 3000  R 1002  A 1010
0
1 z
2 R 5001  E 4000
1 z 2
2 xy z
3 A 8000  E 1001  E 2000

So for now, what I want to do(though not really what I need to do) is just to have the scanner isolate the "A" in the input and print out the four digit number that follows it. However, for some reason, the scanner only detects the last A and only prints "8000" but not the "1010" that comes before it. I assume this is somewhat related to me misusing next(), but I am not sure what I am doing wrong. Any ideas?