Wednesday, February 23, 2011

Solution of Question 3 - REVISED

class CalendarDemo {
public static void main(String args[]) throws IOException
{
String months[] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
String wday[] = {" ", "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};

String date;
Calendar calendar = Calendar.getInstance();
int d,m,y;
BufferedReader ob=new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter Date in the format dd/mm/yy ");
date=ob.readLine();
StringTokenizer b=new StringTokenizer(date,"/");
d=Integer.parseInt(b.nextToken());
m=Integer.parseInt(b.nextToken());
y=Integer.parseInt(b.nextToken());

calendar.clear();
calendar.set(Calendar.YEAR, y);
calendar.set(Calendar.MONTH, m-1);
calendar.set(Calendar.DATE, d);

System.out.print("Date: ");
System.out.print(months[calendar.get(Calendar.MONTH)]);
System.out.print(" " + calendar.get(Calendar.DATE) + " ");
System.out.println(calendar.get(Calendar.YEAR));
System.out.println(wday[calendar.get(Calendar.DAY_OF_WEEK)]);

}
}

1 comment:

Sounak said...

Okay, Sir..

How sure are you of these questions coming in the exam..

I mean what are the chances??