Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Linux Archive
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 07-31-2007, 05:12 AM
zoe zoe is offline
Member
 
Join Date: Jul 2007
Posts: 40
zoe is on a distinguished road
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
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.
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.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 07-31-2007, 06:01 AM
Senior Member
 
Join Date: Jul 2007
Posts: 1,222
hardwired is on a distinguished road
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); } }
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
About JOptionPane.showMessageDialog jhetfield18 AWT / Swing 2 11-03-2007 12:45 AM
About JOptionPane.showMessageDialog jhetfield18 Advanced Java 0 11-02-2007 12:56 PM
Reading in data from file line by line bluekswing New To Java 1 10-02-2007 02:19 AM
new screen tha_crazy New To Java 2 08-15-2007 11:30 AM
Write an application that displays the numbers 1 to 4 on the same line toby New To Java 1 07-23-2007 06:33 PM


All times are GMT +3. The time now is 11:06 PM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org