Page 92 - iPro_trackGPT_V5_Class8
P. 92

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 +" × "+i+ " = "+ number * i);
                          i++;
                      }
                      while (i <= 10);
                  }
                  }





                        Conditional statements help the program to make decisions.
                        Conditional statements are also referred to as decision-making statement.
                        Looping  statements  are  control  flow  statements  that  let  us  repeatedly  run  a  set  of
                        instructions for a specified number of times.
                        The break statement in Java is used to stop a loop or switch statement before it finishes
                        all its steps.

                        The continue statement skips the rest of the current loop cycle and goes directly to the
                        next iteration, without running the code that comes after it in that cycle.
                        An error is an abnormal condition that can stop the execution of a program.




                    90    TrackGPT iPRO (V5.0)-VIII
   87   88   89   90   91   92   93   94   95   96   97