This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
Welcome to the Ranch! Please UseCodeTags when you post source code, and make sure your code is properly indented. That way it is much easier to read. Being a moderator on the forum here, I have added the code tags to your post above.
What do you mean with "the while loop doesn't exit"; what happens when you enter -1 for the gallons?
I tried running your program, and when I enter -1 for the gallons, it first asks for the miles and then exits, as you would expect.