Page 144 - computer science (868) class 11
P. 144

After correcting it, the program returns the following output:
              Enter the length and breadth
              20
              10
              Perimeter 60
              Area 200


                   7.3 COMPOUND STATEMENTS
              When a group of statements is written within a curly bracket, then it is known as a compound statement. This group
              of statements executes together in a sequential manner to provide the result.
              These statements are useful for all types of conditional and iterative statements.
              For example,

                  if(a>b && a>c)
                  {
                      System.out.println(a+ "is largest");
                      System.out.println(b + " and" +c+ "are less than" +a);
                  }
                  else
                  if(b>a && b>c)
                  {
                      System.out.println(b+ "is largest");
                      System.out.println(a+ "and" +c+ "are less than" +b);
                  }
                  else
                  {
                      System.out.println(c+ "is largest");
                      System.out.println(a+ "and" +b+ "are less than" +c);
                  }

                   7.4 CONTROL STATEMENTS
              As we have already learnt that the control statements control the flow of a program. They
              determine whether the statements will be executed or not based on certain conditions.   Statement 1
              There are three types of control statements which are as follows:

              •  Sequential Statements                                                                Statement 2
              •  Conditional Statements
              •  Iterative Statements                                                                 Statement 3
              Let us learn about them in detail.

              7.4.1 Sequential Statement

              In Java, the statements are executed sequentially which represents the default flow of statements. In the default flow
              of statements, the compiler executes the first statement and then goes to the next statement for its execution and so
              on, unless it receives a conditional or an iterative statement. The sequential statement follows the top-down approach.

              The following program shows the sequential flow of statements.
                  //Program to input the cost of 35 pens and print the cost of n pens



                142142  Touchpad Computer Science-XI
   139   140   141   142   143   144   145   146   147   148   149