| | |
how to print out an array in a message box
Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Oct 2004
Posts: 44
Reputation:
Solved Threads: 0
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?
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?
that is likely not what was intended, as it shows a separate messagebox for each element of the array 
better would be something like
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.

better would be something like
Java Syntax (Toggle Plain Text)
StringBuilder builder = new StringBuilder(p.length); for (int i=0;i<p.length;builder.append(p[i++])) builder.append("\n"); 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.
•
•
Join Date: Mar 2008
Posts: 2
Reputation:
Solved Threads: 0
•
•
•
•
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)
StringBuilder builder = new StringBuilder(p.length); for (int i=0;i<p.length;builder.append(p[i++])) builder.append("\n"); 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.
![]() |
Similar Threads
- Scanner & Message Box (Java)
- Turning my board from console to Message box (Java)
- Time Release Message Box (C)
- download message box's events (ASP)
- how to set up my for loop to print my array in reverse (Java)
- repeating the whole program after pressing Yes button in the confirmation message box (Java)
Other Threads in the Java Forum
- Previous Thread: Help!
- Next Thread: reading from file
| Thread Tools | Search this Thread |
android api applet application array arrays automation awt bidirectional binary birt bluetooth businessintelligence busy_handler(null) calculator chat class classes client code columns component constructor database designadrawingapplicationusingjavajslider draw eclipse editor error errors event eventlistener exception expand fractal game givemetehcodez graphics gui guidancer html ide image inetaddress input integer intellij j2me java javafx javamicroeditionuseofmotionsensor javaprojects jme jni jpanel jtree julia link linux list loop map method methods mobile mobiledevelopmentcreatejar myaggfun netbeans newbie oracle parsing plazmic print problem program programming project recursion scanner screen server set sharepoint size smart sms smsspam sort sortedmaps sql string subclass support swing threads time tree unlimited webservices windows






