Results 1 to 2 of 2
- 07-31-2007, 03:12 AM #1
Member
- Join Date
- Jul 2007
- Posts
- 40
- Rep Power
- 0
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
maybe?Java Code:If (count % 5 == 0); temp = temp + "/n";
Here is what I have at the moment. I am really stuck on how to implement the return character.
Thanks.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); } }
- 07-31-2007, 04:01 AM #2
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
-
new screen
By tha_crazy in forum New To JavaReplies: 4Last Post: 02-16-2011, 10:46 AM -
About JOptionPane.showMessageDialog
By jhetfield18 in forum AWT / SwingReplies: 2Last Post: 11-02-2007, 10:45 PM -
About JOptionPane.showMessageDialog
By jhetfield18 in forum Advanced JavaReplies: 0Last Post: 11-02-2007, 10:56 AM -
Reading in data from file line by line
By bluekswing in forum New To JavaReplies: 1Last Post: 10-02-2007, 12:19 AM -
Write an application that displays the numbers 1 to 4 on the same line
By toby in forum New To JavaReplies: 1Last Post: 07-23-2007, 04:33 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks