User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the Java section within the Software Development category of DaniWeb, a massive community of 456,563 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,515 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Java advertiser: Lunarpages Java Web Hosting
Views: 1110 | Replies: 3
Reply
Join Date: Oct 2007
Posts: 4
Reputation: atrix415 is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
atrix415 atrix415 is offline Offline
Newbie Poster

Display Calculations to a Dialog Box

  #1  
Oct 20th, 2007
hi, I seem to gotten my code run. But what I want is to display everything into a dialog box all at once. So when I type 3 it would display all the factorials starting from three...to 15 and display them according to number / Factorials.
5 to 15 all the factorials. It is only showing them in order now. Can someone give me some help?

Number Factorial
!1 ------ 1
!2 ------ 2
!3 ------ 6
!4 ------ 24

!15 ------ 2004310016





import javax.swing.*; // program uses class JOptionPane

public class Factorial
{
public static void main( String args[] )
{
String integerInput;
int input;
int factorial;

integerInput = JOptionPane.showInputDialog("Enter a Factorial between 1-15:");
input = Integer.parseInt( integerInput);

// for ( input = 1; input <= 15; input++ )
{

factorial = 1;

for ( int numLess = 1; numLess <= input; numLess++ )
factorial *= numLess;

//display the message to user
JOptionPane.showMessageDialog(null, " Factorials of " + input + " is " Factorial;

} // end for loop
} // end main
} // end class Factorial
Last edited by atrix415 : Oct 20th, 2007 at 8:59 pm.
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Feb 2006
Posts: 1,517
Reputation: masijade is a glorious beacon of light masijade is a glorious beacon of light masijade is a glorious beacon of light masijade is a glorious beacon of light masijade is a glorious beacon of light 
Rep Power: 10
Solved Threads: 136
masijade's Avatar
masijade masijade is online now Online
Posting Virtuoso

Re: Display Calculations to a Dialog Box

  #2  
Oct 20th, 2007
Rather than showing the message dialog in the loop. simply concatenate to a string, then show the message dialog once after the loop.
Java Programmer and Sun Systems Administrator

----------------------------------------------

Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
Reply With Quote  
Join Date: Oct 2007
Posts: 4
Reputation: atrix415 is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
atrix415 atrix415 is offline Offline
Newbie Poster

Re: Display Calculations to a Dialog Box

  #3  
Oct 22nd, 2007
Can you show me a example of how I can do that?
Reply With Quote  
Join Date: Feb 2006
Posts: 1,517
Reputation: masijade is a glorious beacon of light masijade is a glorious beacon of light masijade is a glorious beacon of light masijade is a glorious beacon of light masijade is a glorious beacon of light 
Rep Power: 10
Solved Threads: 136
masijade's Avatar
masijade masijade is online now Online
Posting Virtuoso

Re: Display Calculations to a Dialog Box

  #4  
Oct 22nd, 2007
Well, according to your other thread http://www.daniweb.com/forums/thread93550.html, you know how to do the Dialog part, and I believe that if you are smart enough to build a switch with properly alinged fall through cases, that you should be smart enough to append strings in a loop. Give it a try, and if it doesn't work, then post it here and we will help correct it. But judging by the fact that your code is always left-aligned, even though code tags are used, I have the feeling that most (if not all) of it, is simply copied of the forums anyway.
Java Programmer and Sun Systems Administrator

----------------------------------------------

Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb Java Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the Java Forum

All times are GMT -4. The time now is 5:43 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC