Page 159 - CA_Blue( J )_Class9
P. 159
5 {
6 Scanner sc= new Scanner (System.in);
7 int n1,n2, n3, sum;
8 double avg;
9 System.out.print("Enter 1st number: ");
10 n1=sc.nextInt();
11 System.out.print("Enter 2nd number: ");
12 n2=sc.nextInt();
13 System.out.print("Enter 3rd number: ");
14 n3=sc.nextInt();
15 sum=n1+n2+n3;
16 avg = sum/3.0;
17 System.out.println("Sum of the numbers: "+sum);
18 System.out.println("Average: "+avg);
19 }
20 }
You will get the following output:
Here, the execution starts with the statement “class sum_and_average” and continues till the end in a
sequential manner.
8.1.2 Conditional Flow of Control
When according to the need of the programmer, the flow of a program is altered depending on a condition, it is
known as the conditional flow of control. In other words, the program control executes the required statement
depending on the condition stated.
Java provides various procedures to control the flow a program according to the need, which are given below:
• if statement
• if-else statement
• Multiple if statements
Conditional Constructs in Java 157

