inside while loop put a condition when u want to exit........in that condition give System.exit(0). .........
Don't use System.exit(0) unnecessarily. Instead try having a boolean variable as a "flag" and have a conditional execution based upon its value. Make sure you set the flag variables value once you have reached the condition.
Use the features sparingly. Just because its present does not mean you can use everywhere.
Comment