Search code examples
javaloopsfor-loopjoptionpane

JoptionPane using for loop


Please Help me with following problem.

I have this program and I have to print out everything in just one JOptionPane message dialog box. Can anyone help me? Here's the code:

   public static void main(String[] args) {


       for(int i = 0; i < 12; i++)
      JOptionPane.showMessageDialog(null, i);

Thanks!


Solution

  • You have a for loop and you want to keep on printing the text from the for loop in your JOption pane...And you want to display ALL of the text:

    To do this, you can use StringBuilder, and the append method.

    StringBuilder LOLOL= new StringBuilder();
    buff.append( "ADD THIS" ).append("\n");              
    

    So now, all of the strings will be together.