please write with Javawhen you enter a monthgive this months

please write with Java,when you enter a month,give this month\'s calendar of 2011.When you enter a year,give this year\'s calendar,and it requests every line showing three months.please give me the code,thank you very much.

Solution

import java.util.Scanner;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
public class CalendarPrint{


    private static String dayOfWeek(int date, int month, int year) {
        Calendar calendar = Calendar.getInstance();
        calendar.set(year, (month - 1), date);
        Date dat = calendar.getTime();
        DateFormat dateFormat = new SimpleDateFormat(\"EEE\");
        String string = dateFormat.format(dat);
        return string;
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        System.out.print(\"Enter month: \");
        int month = sc.nextInt();
        System.out.print(\"Enter year: \");
        int year = sc.nextInt();
        System.out.println(\"The days of month \"+month+\" of year 2011:\ \ \");
        int num_days[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
        for (int i=1; i<=num_days[month-1]; i++){
            System.out.print(i+\": \"+dayOfWeek(i, month, 2011)+\"\\t\");
        }

        System.out.println(\"\ \ Calendar of the year \"+year+\":\ \ \");
        for(int j=1; j<=12; j++){
            for (int i=1; i<=num_days[j-1]; i++){
                System.out.print(i+\": \"+dayOfWeek(i, j, year)+\"\\t\");
            }
        }
    }
}

please write with Java,when you enter a month,give this month\'s calendar of 2011.When you enter a year,give this year\'s calendar,and it requests every line sh

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site