Page 91 - TP_iPlus_V2.1_Class8
P. 91
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
}
}
To Sum Up
Conditional statements allow us to change the default flow of a program.
Looping statements are the control flow statements that allow us to repeatedly execute
a set of statements a given number of times.
Java offers two jump statements – break and continue – which are used within the
loops.
An error is an abnormal condition that can stop the execution of a program.
89
Conditional, Looping and Jump Statements in Java

