Results 1 to 2 of 2
Thread: Problems with Calendar exercise
- 11-20-2007, 04:33 PM #1
Member
- Join Date
- Nov 2007
- Posts
- 1
- Rep Power
- 0
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?) :confused:
I need alot of help and explaining for this as I am absolutly new to java. Any help or advice would be appreciated. Thanks. :)
- 11-20-2007, 07:30 PM #2
Java 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())); } }
Similar Threads
-
exercise of recursive method
By amexudo in forum New To JavaReplies: 2Last Post: 03-09-2008, 05:55 PM -
Prob with an exercise
By jhetfield18 in forum New To JavaReplies: 4Last Post: 02-15-2008, 06:11 PM -
I/O exercise
By Feldom in forum New To JavaReplies: 1Last Post: 10-28-2007, 04:48 PM -
help with exercise
By e_as're in forum New To JavaReplies: 3Last Post: 09-25-2007, 10:14 AM -
help with an exercise calcuting tax
By e_as're in forum New To JavaReplies: 7Last Post: 08-01-2007, 03:17 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks