Script #2 – Leap Year
Description: Given a year, report if it is a leap year.
Purpose: Learn the use of if statements.
Instructions: Complete this assignment to make sure that you know how to use if statements in Powershell.
|
File: leapyear.ps1
Code:
$year = read-Host -Prompt 'Enter the year'
if($year % 4 -eq 0) {
if ($year % 100 -eq 0) {
if($year % 400 -eq 0) {
write-host("This is Leap Year")
}
else{
write-host("Not a leap year")
}
}
else {
write-host("This is a leap year")
}
}
else {
write-host("Not a leap Year")
}
Get Answers For Free
Most questions answered within 1 hours.