how to print out an array in a message box

Reply

Join Date: Oct 2004
Posts: 44
Reputation: ultimate_fusion is an unknown quantity at this point 
Solved Threads: 0
ultimate_fusion ultimate_fusion is offline Offline
Light Poster

how to print out an array in a message box

 
0
  #1
Nov 30th, 2004
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?
Reply With Quote Quick reply to this message  
Join Date: Oct 2004
Posts: 15
Reputation: Dounia is an unknown quantity at this point 
Solved Threads: 0
Dounia Dounia is offline Offline
Newbie Poster

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

 
0
  #2
Nov 30th, 2004
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
Reply With Quote Quick reply to this message  
Join Date: Nov 2004
Posts: 6,144
Reputation: jwenting is just really nice jwenting is just really nice jwenting is just really nice jwenting is just really nice 
Solved Threads: 212
Team Colleague
jwenting's Avatar
jwenting jwenting is offline Offline
duckman

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

 
0
  #3
Dec 1st, 2004
that is likely not what was intended, as it shows a separate messagebox for each element of the array
better would be something like
  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.
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 2
Reputation: franchav is an unknown quantity at this point 
Solved Threads: 0
franchav franchav is offline Offline
Newbie Poster

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

 
0
  #4
Apr 20th, 2008
Originally Posted by jwenting View Post
that is likely not what was intended, as it shows a separate messagebox for each element of the array
better would be something like
  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?
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC