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

Write a program segment that decides whether a given year is a leap year or not.

ID: 3527710 • Letter: W

Question

Write a program segment that decides whether a given year is a leap year or not. A year is a leap year if it is divisible by 4, except for the case when it is also divisible by 100 and not by 400 hundred. So, for example, 1999 is not a leap year because it is not divisible by 4; 2000 is a leap year because it is divisible by 4 and although it is divisible by 100, it is also divisible by 400; 1900 however, is not a leap year because it is divisible by 100 and not by 400. Finally, 2004 is a leap year because it is divisible by 4 and not by 100. Your code should use an int named year for comparisons and print "LEAP YEAR" if the value in year is a leap year and "NOT A LEAP YEAR" if it is not. HINT: You will need to use nested if statements in this code!

Explanation / Answer

import java.io.*; class Year { public static void main(String args[]); Scanner reader = new Scanner(System.in); System.out.println("Enter year"); //get user input for a year=reader.nextInt(); if (year%400.equal(0)) system.out.ptrinln("year is leap year"); else if (year%100.equal(0)) system.out.ptrinln("year is not leap year"); else if(year%4.equal(0)) system.out.ptrinln("year is leap year"); else system.out.ptrinln("year is not leap year"); }

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote