我想输出一个数组,比如int[] a={1,2,3,4,5}。我想达到的输出效果是1 2 3 4 5。但我现在只能是一个对话框一个对话框的输出,变成第一个对话框输出1,第二个对话框输出2....。看起来很不直观,所以请教大虾有没有办法将数组a的所有元素都显示在一个对话框里面。不甚感激!!!
{code}
import javax.swing.JOptionPane;
public class TestOutput {
public static void main(String[] args){
int[] a={1,2,3,4,5};
for (int i = 0; i < a.length; i++)
// System.out.print(a[i] + " ");
JOptionPane.showMessageDialog(null, "The sort of this Array is:"
+ a[i], "Answer", JOptionPane.INFORMATION_MESSAGE);
}
}{code}
{code}
import javax.swing.JOptionPane;
public class TestOutput {
public static void main(String[] args){
int[] a={1,2,3,4,5};
for (int i = 0; i < a.length; i++)
// System.out.print(a[i] + " ");
JOptionPane.showMessageDialog(null, "The sort of this Array is:"
+ a[i], "Answer", JOptionPane.INFORMATION_MESSAGE);
}
}{code}
public class TestOutput {
public static void main(String[] args){
int[] a={1,2,3,4,5};
String out = new String();
for (int i = 0; i < a.length; i++)
{
if (i == 0) {
out = String.valueOf(a[i]);
} else {
out = out + "," + a[i];
}
}
JOptionPane.showMessageDialog(null, "The sort of this Array is:"
+ out, "Answer", JOptionPane.INFORMATION_MESSAGE);
}
public class TestOutput {
public static void main(String[] args){
int[] a={1,2,3,4,5};
StringBuffer out = new StringBuffer();
for (int i = 0; i < a.length; i++)
{
if (i == 0) {
out = String.valueOf(a[i]);
} else {
out = out + "," + a[i];
}
}
JOptionPane.showMessageDialog(null, "The sort of this Array is:"
+ out.toString(), "Answer", JOptionPane.INFORMATION_MESSAGE);
}
import javax.swing.JOptionPane;
public class TestOutput {
public static void main(String[] args){
int[] a={1,2,3,4,5};
StringBuffer out = new StringBuffer();
for (int i = 0; i < a.length; i++)
{
out.append(a[i]);
}
JOptionPane.showMessageDialog(null, "The sort of this Array is:"
+ out.toString(), "Answer", JOptionPane.INFORMATION_MESSAGE);
}