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 7712853
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T01:43:50+00:00 2026-06-01T01:43:50+00:00

public class Sample { public static void main(String[] args) { int year = 2012;

  • 0
public class Sample {
    public static void main(String[] args) {
        int year = 2012;

        // put the month you want
        int month = Calendar.MARCH;

        Calendar cal = new GregorianCalendar(year, month, 1);
        do {
            int day = cal.get(Calendar.DAY_OF_WEEK);
            if (day == Calendar.SATURDAY || day == Calendar.SUNDAY) {
                System.out.println(cal.get(Calendar.DAY_OF_MONTH));
            }
            cal.add(Calendar.DAY_OF_YEAR, 1);
        }  while (cal.get(Calendar.MONTH) == month);
    }

By the above code i am getting all saturdays and sundays in a given month .I want store all these days in an array and the other days in another String array.

  • 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-01T01:43:51+00:00Added an answer on June 1, 2026 at 1:43 am

    Not sure what you mean by reaming days, but if I understand the first part of your question correctly, this should work:

    public static void main(String[] args) {
        int year = 2012;
    
        // put the month you want
        int month = Calendar.MARCH;
    
        Calendar cal = new GregorianCalendar(year, month, 1);
        List<String> saturdaysAndSundays = new ArrayList<String>();
        List<String> otherDays = new ArrayList<String>();
        do {
            int day = cal.get(Calendar.DAY_OF_WEEK);
            String dayInMonth = Integer.toString(cal.get(Calendar.DAY_OF_MONTH));
            if (day == Calendar.SATURDAY || day == Calendar.SUNDAY) {
                saturdaysAndSundays.add(dayInMonth);
            } else {
                otherDays.add(dayInMonth);
            }
            cal.add(Calendar.DAY_OF_YEAR, 1);
        }  while (cal.get(Calendar.MONTH) == month);
        //In case you really want an array:
        String[] array = saturdaysAndSundays.toArray(new String[0]);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

package pack; public class sample{ public static void main(String input[]) { NumberFormat numberFormat =
Here is a sample code: public class TestIO{ public static void main(String[] str){ TestIO
My sample code is as follows: public class ExceptionsDemo { public static void main(String[]
public class Bird { private static int id = 0; private String kind; public
Given the following code sample: public class WeirdStuff { public static int doSomething() {
Assume I have a class that looks like this: class Sample { public string
Sample code: public class Service1 { public int Service1() { .... } } public
Here's the sample code: class TestAO { int[] x; public TestAO () { this.x
class Sample { public static T M<T, TParam1>(TParam1 param1) { return default(T); } }
Consider this code sample: public abstract class Parent { public int val; public Parent()

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.