Page 219 - ComputerScience_Class_11
P. 219
8 boolean flag1, flag2, flag3;
9 System.out.print("Enter the year to be checked : ");
10 year = sc.nextInt();
11 flag1 = (year % 4) == 0;
12 flag2 = (year % 100) != 0;
13 flag3 = ((year % 100 == 0) && (year % 400 == 0));
14
15 if (flag1 && (flag2 || flag3))
16 {
17 System.out.println(year + " is a leap year");
18 }
19 else
20 {
21 System.out.println(year + " is not a leap year");
22 }
23 }
24 }
The output of the preceding program is as follows:
BlueJ: Terminal Window - Java
Options
Enter the year to be checked : 2020
2020 is a leap year
Write a Java program to calculate the following according to the user’s choice:
Program 6
Choice r: Area of a rectangle
Choice i: Area of an isosceles triangle
Choice c: Area of a circle
1 import java.util.*;
2 class geometry
3 {
4 public static void main(String args[])
5 {
6 Scanner sc= new Scanner(System.in);
7 int l, b, arec;
8 double r, acir, s1, s2, aiso;
9 char ch;
10 System.out.println("Choice r: Area of a rectangle");
11 System.out.println("Choice i: Area of an isosceles triangle");
12 System.out.println("Choice c: Area of a circle");
Statements and Scope 217

