943,404 Members | Top Members by Rank

Ad:
  • Java Discussion Thread
  • Unsolved
  • Views: 14326
  • Java RSS
Nov 30th, 2004
0

how to print out an array in a message box

Expand Post »
as above.
e.g
int[] array = new int[can be any size]

joptionpane.showmessagebox(null,
"what to put here is the question"
"messageboxtitle"
joptionpane.informationmessage};
//dont correct the message box crap i was in a rush i know how to do it

e.g
array 1 = 1
array 2 = 5
array 3 = 3
array 4 = 2

the array can be any size thats the problem so i can't just put
"array 1"+ array[0]
"array 2"+ array[1] etc

i can use a for loop when outputting it in a dos window but what can you use for a message box?
Similar Threads
Reputation Points: 10
Solved Threads: 0
Light Poster
ultimate_fusion is offline Offline
44 posts
since Oct 2004
Nov 30th, 2004
0

Re: how to print out an array in a message box

Hi,
Here is a small example how to print an array in Message Box
suppose p is an array:
for( int i = 0;i < p.length; i++)
{ JOptionPane.showMessageDialog(null, p[i], "Printing
results",JOptionPane.INFORMATION_MESSAGE);
}

Hopefully this would help and good luck.
Dounia
Reputation Points: 11
Solved Threads: 0
Newbie Poster
Dounia is offline Offline
15 posts
since Oct 2004
Dec 1st, 2004
0

Re: how to print out an array in a message box

that is likely not what was intended, as it shows a separate messagebox for each element of the array
better would be something like
Java Syntax (Toggle Plain Text)
  1. StringBuilder builder = new StringBuilder(p.length);
  2. for (int i=0;i<p.length;builder.append(p[i++])) builder.append("\n");
  3. JOptionPane.showMessageDialog(null, builder.toString(), "Printing results", JOptionPane.INFORMATION_MESSAGE);

this will put each element of the array onto its own line.

When using Java versions lower than 1.5 use StringBuffer instead of StringBuilder.
Team Colleague
Reputation Points: 1658
Solved Threads: 331
duckman
jwenting is offline Offline
7,719 posts
since Nov 2004
Apr 20th, 2008
0

Re: how to print out an array in a message box

Click to Expand / Collapse  Quote originally posted by jwenting ...
that is likely not what was intended, as it shows a separate messagebox for each element of the array
better would be something like
Java Syntax (Toggle Plain Text)
  1. StringBuilder builder = new StringBuilder(p.length);
  2. for (int i=0;i<p.length;builder.append(p[i++])) builder.append("\n");
  3. JOptionPane.showMessageDialog(null, builder.toString(), "Printing results", JOptionPane.INFORMATION_MESSAGE);

this will put each element of the array onto its own line.

When using Java versions lower than 1.5 use StringBuffer instead of StringBuilder.
How would you to the same to a two dimensional array?
Reputation Points: 10
Solved Threads: 0
Newbie Poster
franchav is offline Offline
2 posts
since Mar 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Java Forum Timeline: Help!
Next Thread in Java Forum Timeline: reading from file





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC