Ok, so what is the format of the text file?
I would assume you have more than 2 subject names and you are wanting to test each against each other.
Consider the code you have above. In the while loop, you are asking input to give you the next, then the next again. It is important to remember that the next method moves the imaginary placeholder on the scanner object. So, here is a description of what is happening:
Loop 1: Subject 1 compared to Subject 2
Loop 2: Subject 3 compared to Subject 4
Loop 3: Subject 5 compared to Subject 6
ect.
What you want to do (if my assumption of your goal is correct) is to read in each subject, store it in a data structure (such as an array, ArrayList, Vector, ect.), then go through the data structure and compare each Subject to all the other Subjects in the data structure.
Do I get the general idea of what you are doing and does that make sense?