I had just finished updating it to show pretty much what you just did. Thanks. I'm going to break it down piece by piece so I fully understand how each section works. I really appreciate a working example to go off of thank you!
I was lazy and didn't comment it. I'll do that now.
import javax.swing.*;
public class largest {
public static void main(String[] args) {
int largest = 0; //Defines the largest number. We start at 0 as thats the lowest possible number to start at.
int counter = 0; //This keeps track of how many times we have asked for a number
int number = -1; //This keeps track of the current number. Starts at -1 for error handling
while(counter < 10){ //This is a while loop. As long as our counter varible is below 10, we will keep repeating the code. THIS CAN GO ON FOREVER
String name = JOptionPane.showInputDialog("Enter a number between 0 and 9: "); //Ask for their input. No matter what happens, we handle the error with the next line.
try // Lets Try doing something!
{
number = Integer.parseInt(name); //Parse the input into an int. If its not a number, it will throw an error
}
catch (NumberFormatException e) // Lets catch the error
{
number = -1; //Since they didn't put in a number, lets set the number ot -1 so our next statement will tell them its not a single digit
}
if (number >= 0 && number < 10) { //This checks if its a number greater then or equal to 0 AND less then 10. This ensures its a single digit number
if(number > largest){ //Did they give us a number larger then our current largest number?
largest = number; //Update our largest number with the current number!
}
counter++; // Since we did get a valid number between 0 and 9, we can increase the counter variable by 1
}else{ //Not a single digit number (Or a number at all <img src='http://www.neocodex.us/forum/public/style_emoticons/<#EMO_DIR#>/tongue.gif' class='bbc_emoticon' alt=':p' />)
System.out.println("That number is not single digit. Try Again"); //Complain to them!
}
}
System.out.println(largest); //We got 10 numbers, tell them which one was the highest
}
}