Page 195 - Cs_withBlue_J_C11_Flipbook
P. 195
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:
Enter the year to be checked : 2020
2020 is a leap year
Program 6 Write a Java program to calculate the following according to the user’s choice.
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()
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");
13 System.out.println("Enter your choice : ");
193
Statements and Scope 193

