|
|
Hi all,
I'm new here and new to java programming. I have a background in C++.
My question concerns using JOptionPane.showInputDialog twice in a program.
I use it once with some text and then use it again inside a for loop with different text. It keeps the text from the first use instead of changing it when I run the program.
import javax.swing.JOptionPane;
public class Largest {
public static void main(String[] args) {
String num;
int num1 = 0;
int largest = 0;
num = JOptionPane.showInputDialog(null, "Enter 10 numbers one at a time clicking 'OK' each time");
num1 = Integer.parseInt(num);
for(int i = 0; i < 9; i++)
{
//input number
num = JOptionPane.showInputDialog(null, "NEXT NUMBER");
num1 = Integer.parseInt(num);
if (num1 > largest)
largest = num1;
}
JOptionPane.showMessageDialog(null, "The largest number is " + largest,
JOptionPane.INFORMATION_MESSAGE);
System.exit(0);
}
}The program works fine but after the first input dialog the text should change and it doesn't. I've tried using a different variable for the first one but it made no differenc. The second one still used the text from the first one while it's inside the loop.
Can anyone tell me what I'm doing wrong here?
Thanks