Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Linux Archive
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 11-20-2007, 06:33 PM
Member
 
Join Date: Nov 2007
Posts: 1
Jude is on a distinguished road
Problems with Calendar exercise
I have been set a task to display a calendar for any given month and year.
I made a start by using a text book but I cant seem to get what i need from it.

So far I have used GregorianCalendar and I can display a calendar. I first thought it was todays date but it isn't it seems to be a random month and year.
Although I am having alot of problems the biggest problem is that I need to be able to input a given month and year, and then display that.
I have read that I can use scanner or get (I think?)

I need alot of help and explaining for this as I am absolutly new to java. Any help or advice would be appreciated. Thanks.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 11-20-2007, 09:30 PM
Senior Member
 
Join Date: Jul 2007
Posts: 1,222
hardwired is on a distinguished road
Code:
import java.text.*; import java.util.*; public class Test { public static void main(String[] args) { // Calendar practice. DateFormat df = new SimpleDateFormat("dd MMM yyyy"); Date now = Calendar.getInstance().getTime(); System.out.println("now = " + now); System.out.println("now = " + df.format(now)); Calendar calendar = Calendar.getInstance(); calendar.set(Calendar.MONTH, Calendar.MAY); System.out.println("set to May = " + df.format(calendar.getTime())); calendar.set(1997, 8, 24); System.out.println("set to 1997 = " + df.format(calendar.getTime())); calendar.roll(Calendar.DAY_OF_MONTH, 7); System.out.println("7 days ahead = " + df.format(calendar.getTime())); // Try some input. Scanner scanner = new Scanner(System.in); System.out.println("enter a four digit year"); int year = scanner.nextInt(); System.out.println("enter a Month"); int month = scanner.nextInt(); System.out.println("Enter a day of the month"); int day = scanner.nextInt(); System.out.printf("year = %d month = %d day = %d%n", year, month, day); scanner.close(); calendar.set(year, month, day); System.out.println("you entered " + df.format(calendar.getTime())); } }
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
exercise of recursive method amexudo New To Java 2 03-09-2008 07:55 PM
Prob with an exercise jhetfield18 New To Java 4 02-15-2008 08:11 PM
I/O exercise Feldom New To Java 1 10-28-2007 06:48 PM
help with exercise e_as're New To Java 3 09-25-2007 12:14 PM
help with an exercise calcuting tax e_as're New To Java 7 08-01-2007 05:17 AM


All times are GMT +3. The time now is 03:42 AM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org