Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

JAVA HELP boolean leapyear = (year % 4 == 0 && year % 100 != 0) (year % 400 = 0)

ID: 3668277 • Letter: J

Question

JAVA HELP

boolean leapyear = (year % 4 == 0 && year % 100 != 0)

(year % 400 = 0)

Use the statements above in your program.

Connect the two statements above with a short-circuit operator, make sure code is correct, and create a program where the user can enter an integer year using the new Scanner (System.in); method and be returned a true if the year is a leap year or false if the year is not a leap year.

Sample Outputs

“Enter Year” // User prompt

2000

“2000 is a leap year? true” // Output

“Enter Year” // User prompt

190

“190 is a leap year? false” // Output

Explanation / Answer

import java.util.*;
import java.lang.*;
import java.io.*;

import java.util.Scanner;

class checkLeapYear {

   int year;
   Scanner scan;
  
   void check() {
      
  
       System.out.println(" Enter Year : ");
       scan = new Scanner(System.in);
      
       year = Integer.parseInt(scan.nextLine());
      
   if((year % 400 == 0) || ((year % 4 == 0) && (year % 100 != 0)))
           System.out.println(year + " is a leap year ?true");

       else
           System.out.println(year + " is a leap year?false");
   }
}

class MainClass {
  
   public static void main(String str[]) {
      
       checkLeapYear obj = new checkLeapYear();
      
       obj.check();
   }
}

Out Put: