as part of the program iam writing there is to be an option for the user to enter a number to obtain the facotrial of. So far i have this:
number = Integer.parseInt(JOptionPane.showInputDialog("\nPlease enter the number you wish to obtain the factorial for"));
JOptionPane.showMessageDialog(null, "You entered the number: " + number);
count = (number - 1);
if(number > 1)
{
do
{
factorial = number * count;
JOptionPane.showMessageDialog(null, number + " * " + count + " = " + factorial);
count--;
number = factorial;
}
while(count > 0);
JOptionPane.showMessageDialog(null, number + " * " + count + " = " + factorial);
JOptionPane.showMessageDialog(null, "The facorial of " + number + " is " + factorial);
}
else if (number == 0)
{
JOptionPane.showMessageDialog(null, "Factorial of 0 is 1");
}
else if (number == 1)
{
JOptionPane.showMessageDialog(null, "Factorial of 1 is 1");
}
else if (number < 0)
{
JOptionPane.showMessageDialog(null, "Please enter a number equal to or greater than 0");
This works fine but the brief is to also include an error message prompting the user ro enter a whole number when a decmimal number has been used and also if a letter is inputted. I am struggling to write code to achieve this.
Thanks in advance
Ryan