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

  • SEARCH
  • Home
  • 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 8929575
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T08:42:09+00:00 2026-06-15T08:42:09+00:00

I am trying to figure out how to make my program count the number

  • 0

I am trying to figure out how to make my program count the number of Sundays in a week.

I have tried the following thing:

if (date.DAY_OF_WEEK == date.SUNDAY) {
    System.out.println("Sunday!");
}

Yet it does not seem to work?

When I try to System.out.Println the date.DAY_OF_WEEK I get: 7

Does anyone know how I can check if the current calendar date is Sunday?

UPDATE FOR MORE INFORMATION

  1. firt of all the date.DAY_OF_WEEK is a Calendar object!

  2. i made sure to set the Calendar object date to a sunday

The system out print where i get 7 is what it returns to me when i try to run date.DAY_OF_MONTH even if the day it set to a sunday

2nd UPDATE TO ALEX

This is more or less my code

Calendar startDate = Calendar.getInstance();

    startDate.set(2012, 12, 02);
    if (startDate.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY) {
        System.out.println("true");
    }else {
        System.out.println("FALSE");
    }
  • 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-15T08:42:10+00:00Added an answer on June 15, 2026 at 8:42 am
    Calendar cal = ...;
    if (cal.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY) {
        System.out.println("Sunday!");
    }
    

    Calendar.DAY_OF_WEEK always equals to 7 no matter what instance of Calendar you are using (see this link), it is a constant created to be used with the Calendar.get() method to retrieve the correct value.

    It is the call to Calendar.get(Calendar.DAY_OF_WEEK) that will return the real day of week. Besides, you will find useful values in the Calendar class like Calendar.SUNDAY (and the other days and months) in order for you to be more explicit in your code and avoid errors like JANUARY being equal to 0.

    Edit

    Like I said, the Calendar class does contains useful constants for you to use. There is no month number 12 they start at 0 (see above), so DECEMBER is month number 11 in the Java Date handling.

    Calendar startDate = Calendar.getInstance();
    startDate.set(2012, Calendar.DECEMBER, 02);
    if (startDate.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY) {
        System.out.println("true");
    } else {
        System.out.println("FALSE");
    }
    

    Will print true of course.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to figure out how to make my layout have the following
I'm trying to figure out a way to make demos for a program I've
I've been trying to figure out this problem. I have an assignment to make
For few days I have been trying to figure out how to use make
I'm trying to figure out how to make it so that when I'm moving
I'm trying to figure out how to make jQuery slide #content2 down and replace
I've been trying to figure out how I can make a query with MySQL
I'm trying to figure out how if there's a way to make a hostname
I'm trying to figure out how my iOS app should work after Facebook make
I'm trying to make getJSON to use JSONP object, but I can't figure out

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.