0% found this document useful (0 votes)
54 views1 page

Activity 2 Code

The Java code defines a class called Activity2 that contains a main method to run a loop that prompts the user to enter a year and checks if it is a leap year. It continues looping and checking years until the user enters 'N' or 'n' when asked if they want to continue. The isLeapYear method is called in the loop to get the year input and determine if it satisfies the leap year rules or not.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
54 views1 page

Activity 2 Code

The Java code defines a class called Activity2 that contains a main method to run a loop that prompts the user to enter a year and checks if it is a leap year. It continues looping and checking years until the user enters 'N' or 'n' when asked if they want to continue. The isLeapYear method is called in the loop to get the year input and determine if it satisfies the leap year rules or not.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

package com.mycompany.

activity2;
import java.util.Scanner;
public class Activity2 {
Scanner sc = new Scanner(System.in);
public static void main(String[] args) {
Activity2 act = new Activity2();
Scanner sc = new Scanner(System.in);
boolean done=true;
while(done){
act.isLeapYear();
System.out.println("");
System.out.println("Would you like to continue, Y/N?");
String ans= sc.nextLine();

done = ans.equals("y")||ans.equals("Y");
if(ans.equals("N")||ans.equals("n")){
done=false;
}
System.out.println("");
}
System.out.println("Thank you!");
}

public void isLeapYear(){


System.out.print("Enter Year: ");
int year = sc.nextInt();

if((year%4==0)&&((year%100!=0)||(year%400==0))){
System.out.println(year+" is a Leap Year.");
}
else{
System.out.println(year+" is not a Leap Year.");
}
}
}

You might also like