Page 88 - iPlus_Ver_2.0_class_8
P. 88

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;
                          }
                          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);
                  }
                  }




                     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 jumping statements – break and continue – which are used within the
                         loops.
                          An error is an abnormal condition that can stop the execution of a program.




                    86
                         iPlus (Ver. 2.0)-VIII
   83   84   85   86   87   88   89   90   91   92   93