Hi all. Your's truly here again.Hope everyone is doing well. Alas, I'm having trouble pointing out what I'm doing wrong here with this little program I'm writing for class. What I need to do is ask the user to input numbers, store them in an array of ten, and then display the largest one. Simple enough I thought. But when I run my program, it just keeps displaying '2' as the largest entry no matter what. I was really happy with the speed at which the code poured out of my n00b brain that I'm really disappointed it's not working. Any thoughts would be appreciated.
import javax.swing.JOptionPane; public class PeerProgram3 { public static void main(String[] args) { final int TOTAL = 10; String input; String newInput; int[] numbers = new int[TOTAL]; JOptionPane.showMessageDialog(null,"I'm going to ask you to input 10 numbers."); input = JOptionPane.showInputDialog("Please enter a number:"); for (int index = 1; index < TOTAL; index++) { newInput = JOptionPane.showInputDialog("Please enter another number"); numbers[index] = Integer.parseInt(newInput); } int highest = numbers[0]; for (int index = 1; index < TOTAL; index++) { if (numbers[index] > highest) highest = numbers[index]; JOptionPane.showMessageDialog(null, "The highest number you entered is " + highest + "."); System.exit(0); } }


LinkBack URL
About LinkBacks
Hope everyone is doing well. Alas, I'm having trouble pointing out what I'm doing wrong here with this little program I'm writing for class. What I need to do is ask the user to input numbers, store them in an array of ten, and then display the largest one. Simple enough I thought. But when I run my program, it just keeps displaying '2' as the largest entry no matter what. I was really happy with the speed at which the code poured out of my n00b brain that I'm really disappointed it's not working. Any thoughts would be appreciated.
Reply With Quote