Results 1 to 2 of 2
  1. #1
    zoe
    zoe is offline Member
    Join Date
    Jul 2007
    Posts
    40
    Rep Power
    0

    Default Displaying numbers per line on a JOptionPane.showMessageDialog screen

    Hi, I am trying to have my program output all the even numbers from 0-500 displaying 5 numbers per line on a JOptionPane.showMessageDialog screen. I can get it to output one number each output box but you need to keep hitting ok. I was thinking of using modulus in an if loop.

    Something like
    Java Code:
    If (count % 5 == 0);
    temp = temp + "/n";
    maybe?

    Here is what I have at the moment. I am really stuck on how to implement the return character.
    Java Code:
    import javax.swing.JOptionPane;
    
    public class Counting
    {
    public static void main(String args[])
    {
    String temp;
    int count=0;
    
    while (count <= 400)
    {
    JOptionPane.showMessageDialog(null, "The output is "+ count);
    count = count + 2;
    }
    if (count % 5 == 0);
    temp = temp + "/n";
    System.exit(0);
    }
    
    }
    Thanks.

  2. #2
    hardwired's Avatar
    hardwired is offline Senior Member
    Join Date
    Jul 2007
    Posts
    1,576
    Rep Power
    9

    Default

    Java Code:
    import javax.swing.JOptionPane;
    
    public class CountingRx
    {
        public static void main(String args[])
        {
            String temp = "";
            int count=0;
            int j = 1;
    
            while (j <= 50)
            {
                j++;
                
                if(j % 2 == 0)    // test for an even number
                {
                    count++;
                    temp += " " + j;
                    if(count % 5 == 0)
                        temp = temp + "\n";
                }
            }
            JOptionPane.showMessageDialog(null, "The output is "+ temp);
            System.exit(0);
        }
    }

Similar Threads

  1. Replies: 5
    Last Post: 06-07-2014, 05:39 PM
  2. new screen
    By tha_crazy in forum New To Java
    Replies: 4
    Last Post: 02-16-2011, 10:46 AM
  3. About JOptionPane.showMessageDialog
    By jhetfield18 in forum AWT / Swing
    Replies: 2
    Last Post: 11-02-2007, 10:45 PM
  4. About JOptionPane.showMessageDialog
    By jhetfield18 in forum Advanced Java
    Replies: 0
    Last Post: 11-02-2007, 10:56 AM
  5. Reading in data from file line by line
    By bluekswing in forum New To Java
    Replies: 1
    Last Post: 10-02-2007, 12:19 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •