Page 91 - iprime_V2.2_class8
P. 91
Output
Program 3: Write a Java program to calculate the factorial of an entered number. The number
should be taken as input from the user.
public class Program3
{
public static void main(int number)
{
int i,fact=1;
for(i=1;i<=number;i++)
{
fact=fact*i;
} Output
System.out.println("Factorial of "+number+" is: "+ fact);
}
}
Program 4: Write a program to print a table with an entered number.
public class Program4
{
public static void main(int number)
{
int i = 1;
System.out.println("The entered number is: "+ number);
System.out.println("Table is:");
do
{
System.out.println(number +" X "+i+ " = "+ number * i);
i++;
}
while (i <= 10);
Output
}
}
Conditional, Loop and Jump Statements in Java 89

