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

Recommended Answers

All 3 Replies

Rather than showing the message dialog in the loop. simply concatenate to a string, then show the message dialog once after the loop.

Can you show me a example of how I can do that?

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.