Can you help me wlth the following work?:
This sample program shows how to print the current month, now using the "Calendar" object (instead of the Date object which has been deprecated, meaning it has been slated for removal from the language).

// Program prints the current month
 
import java.util.Calendar;
 
public class ShowToday {
static String[] monthArray = {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" };
 
public static void main(String[] args) {
Calendar rightNow = Calendar.getInstance();
int month = rightNow.get( Calendar.MONTH );
// This will be a number from 0 to 11, representing January to December
System.out.println("month: " + month );
// Using the above array, this will print "Jan" thru "Dec"
System.out.println("month: " + monthArray[month] );
}
}

:!:

Recommended Answers

All 6 Replies

So what's the question?

So what is the solution to the following:

This sample program shows how to print the current month, now using the "Calendar" object (instead of the Date object which has been deprecated, meaning it has been slated for removal from the language).
// Program prints the current month

import java.util.Calendar;

public class ShowToday {
static String[] monthArray = {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" };

public static void main(String[] args) {
Calendar rightNow = Calendar.getInstance();
int month = rightNow.get( Calendar.MONTH );
// This will be a number from 0 to 11, representing January to December
System.out.println("month: " + month );
// Using the above array, this will print "Jan" thru "Dec"
System.out.println("month: " + monthArray[month] );
}
}

yeah, what is the question?

And no, the Date class is NOT deprecated. It's just had its scope reduced to the task of tracking time, which is what it should have been in the first place.

Apparently you haven't compiled and or run the code

Apparently you haven't realized that we help people here that have questions. Not statements of "Here is my code, whats the matter with it."

- Btw, GregorianCalendar would most likely do everything that you're trying to do.

So what is the solution to the following:

That isn't a question, that's you wanting us to just solve the homework for you. And it isn't going to happen.

So again, whats your question?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.