You should store a variable outside the loop that you change when needed.
Typically, you would set this number equal to the first value, but for this case, you can set it to -1 since that is not something that will change. Try this:
int maxNumber = -1; while(true){ System.out.print("Please enter a number (enter -1 to quit):"); a = user.nextInt(); if(a != -1 && a > maxNumber){ maxNumber = a; else if(a == -1){ // You can do a check here to be sure they even entered a number. if(maxNumber == -1){ System.out.println("No number was input."); } else{ System.out.println("The max number was " + maxNumber); } } }
EDIT for further explanation
What this will do is check that if the user has entered a number that is larger than anything entered yet. If it is, it will change the value to that number. Example: If I type 2, and then 3, maxNumber will become 3. If I type in 0, max number will remain 3. If at any point I type -1, it will break as you have set up already.
EDIT 2
As far as what I meant when I said 'you would set this number equal to the first value' let me explain.
A user can input any value, except -1. So, how do I set the initial max value? If I say maxNumber = 0 and you enter nothing but negatives, I will print 0 as the max number when I am done. That being said, what I have done above is still not fool proof. If the user enters values only less than -1, I still will print an incorrect max. So, it would be best practice to get the first input value, and set that to your max, and change it if a new one is encountered. It would change the code to look like this:
int maxNumber = -1; // Just a junk value to start. boolean firstNumber = true; while(true){ System.out.print("Please enter a number (enter -1 to quit): "); a = user.nextInt(); if(a == -1 && firstNumber){ // If the user enters -1 right away. System.out.println("No number was input."); } else if(a == -1 && !firstNumber){ // If they've entered -1 after inputting a valid number System.out.println("The max number was " + maxNumber); } else{ // They've entered a valid number. if(firstNumber){ // If this is the first number, we set the max initially, and change this flag to false now. maxNumber = a; firstNumber = false; } else{ // Not first number, so only check if the input is larger. if(a > maxNumber){ maxNumber = a; } } } }