Hi again! I like it when there are lots of Java questions
I have modified your code in a few places to make it easier to find the biggest:
Code:
public static void main(String args[]) {
int tick;
int biggest = 0;
int[] arrayuserinput = new int[11];
for (tick = 1; tick < arrayuserinput.length; tick++) {
//variable to hold what the user has entered
int userInput = 0;
//this loop will keep asking the user for the number if they enter an incorrect numer
while (userInput <= 0 || userInput > 29) {
//get the input
userInput = Integer.valueOf(JOptionPane.showInputDialog("Enter Number between 0 and 29\n" + "# " + tick + :"));
}
//put the input out array
arrayuserinput[tick] = userInput;
//use Math.max to find the largest number.
//this is equivalent to:
//if (userInput > biggest)
// biggest = userInput;
biggest = Math.max(userInput, biggest);
}
//tell everyone what the biggest was
JOptionPane.showMessageDialog(null, "Biggest was " + biggest);
// Terminate the Application
System.exit(0);
} Major differences:
+I've changed the arrayuserinput to an int array to hold the numbers the user enters, not the string they have entered
+I've added a while loop. This is the validation stage, if the number is out of range then the condition in the while brackets will be true so the code inside the while block will be executed. Notice with your previous method you could enter an incorrect number if you entered an out of range number twice in a row.
+Added the Math.max function. This simply finds whether out new number is bigger than our current 'biggest' number. If it is, we change 'biggest' to reflect this
Hope that description + the comments will explain it to you
p.s. You can improve validation by checking to see if the user has entered a number, and not something like a letter or a symbol