Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8868137
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T17:11:45+00:00 2026-06-14T17:11:45+00:00

I have an assignment for school to make a program which results in either

  • 0

I have an assignment for school to make a program which results in either true or false. It’s about wether a year is a leap year or not. The problem I have at the moment is that i’m using a public static boolean instead of a public boolean.
This is my code:

public class Assignment {

    static boolean isLeapYear;

    public static void main(String[] args)
    {        
        int year = 2000;
        isLeapYear(year);
    }
    public static boolean isLeapYear(int year) {
        if (((year/100)%4 == 0 && year%4 ==0) || (year % 400 == 0))
            isLeapYear = true;

        else
            isLeapYear = false;

        System.out.println(isLeapYear);

        return isLeapYear;
    }
}

The int year is 2000 at the moment but the rules are like this:
A leap year is a year wich can be divided by 4 unless the year is the beginning of a new century (1700, 1800, 1900…..). So even though you can divide 1900 by 4 you can’t divide it by 400 so it’s false.
So again the question: What do I need to do so i’m able to use a public boolean instead of a public static boolean?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T17:11:47+00:00Added an answer on June 14, 2026 at 5:11 pm

    You would need to create an instance of your class to invoke that method from your main method, if you want to make your method non-static. And then you can make your isLeapYear variable non-static: –

    boolean isLeapYear;
    public static void main(String[] args)
    {        
        int year = 2000;
        new Assigment().isLeapYear(year);
    }
    public boolean isLeapYear(int year) {
        // access isLeapYear as `this.isLeapYear` or just `isLeapYear`
    }
    

    But, precisely, you don’t need to store your result in a boolean variable. If you want to return a boolean value of some expression, then you can just return that expression.

    So, just having this code in your method would also work fine, and it is more readable, and let that method be static: –

    return (((year/100)%4 == 0 && year%4 ==0) || (year % 400 == 0))
    

    And from your main call: –

    System.out.println("Year : " + year + ", is leap year: " + isLeapYear(year));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For a school assignment we have to make a client server chat program in
I have an assignment for school, and I'm not sure how the teacher wants
For a school assignment I have to create a C++ program that will create
For a school assignment, we have to make a Usecase diagram. But the documentation
For a school assignment I have to make a connection to a database from
For an assignment at school, we have to use structs to make matrices that
I have a small school assignment. My output is not correct. Can you see
I have an assignment for school: I need to make a user database. First
For a school assignment I have been told to make a calculator app, the
Hello is have a question for a school assignment i need to : Read

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.