View Single Post
  #1 (permalink)  
Old 03-21-2008, 04:22 AM
Phobos0001 Phobos0001 is offline
Member
 
Join Date: Nov 2007
Posts: 20
Phobos0001 is on a distinguished road
Need help with my 1st array program
Hi again everyone,

ive been working through my textbook and i'm just starting off with arrays, however im having a little trouble getting the output how i want it to go.

the objective is to enter 5 intergers into an array and display the 5 intergers plus the sum of them added together in a dialog box, ive managed to do this in a terminal window however when i use dialog boxes i have a little issue with each element of the aray being displayed in a seporate box, i'm guessing ive messed up with my "for" loops or something, could someone tell me what ive done wrong or point me in the right direction please? here's what ive got so far...

Code:
import javax.swing.*; public class ArrDone { public static void main(String[] args) { final int NUMELS= 5; String s1; int i; int total = 0; // declare and allocate the array int numbers[] = new int[NUMELS]; // allocate the array for (i = 0; i < NUMELS; i++) // Enter the grades { s1 = JOptionPane.showInputDialog("Enter a number: "); numbers[i] = Integer.parseInt(s1); total = total + numbers[i]; } for (i = 0; i < NUMELS; i++) // Display and total the grades { JOptionPane.showMessageDialog(null,"numbers entered where: " + numbers[i] + "\n" + "the sum of all numbers entered is: " + total,"message", JOptionPane.INFORMATION_MESSAGE); } System.exit(0); } }
thanks in advance for any help, its greatly apriciated
Reply With Quote
Sponsored Links