How to ask God how to print the following calendar

package servlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


@WebServlet("/Page1")
public class Page1 extends HttpServlet {
    
    
	private static final long serialVersionUID = 1L;


	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    
    

		response.getWriter().append("Served at: ").append(request.getContextPath());

		int[] lastDay = {
    
     31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };

		int[] startWeek = {
    
     5, 1, 1, 4, 6, 2, 4, 0, 3, 5, 1, 3 };
		int month = 1;
		if (request.getParameter("month") != null) {
    
    
		month = Integer.parseInt(request.getParameter("month"));
		}

		ArrayList<String[]> list = new ArrayList<String[]>();

		String[] row = {
    
     "", "", "", "", "", "", "" };







		response.setContentType("text/html; charset=UTF-8");
		PrintWriter pw = response.getWriter();
		pw.println("<html>");
		pw.println("<head>");
		pw.println("<title>Calendar2</title>");
		pw.println("<link rel=\"stylesheet\"href=\"https://maxcdn.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css\" />");
		pw.println("</head>");
		pw.println("<body style=\"margin:20px;\">");
		pw.println("<h4>Calendar 2021 | </h4>");
		pw.println("<table class=\"table table-striped table-bordered\">");
		pw.println("<thead class=\"thead-dark text-center\">");
		pw.println("<tr><th>Sun</th><th>Mon</th><th>Tue</th>");
		pw.println("<th>Wed</th><th>Thu</th><th>Fri</th><th>Sat</th></tr>");
		pw.println("</thead>");
		pw.println("<tbody style=\"font-size:20px\">");
		for (String[] data : list) {
    
    
		pw.println("<tr class=\"text-center\">");
		pw.println("<td>" + data[0] + "</td>"); // Sun
		pw.println("<td>" + data[1] + "</td>"); // Mon
		pw.println("<td>" + data[2] + "</td>"); // Tue
		pw.println("<td>" + data[3] + "</td>"); // Wed
		pw.println("<td>" + data[4] + "</td>"); // Thu
		pw.println("<td>" + data[5] + "</td>"); // Fri
		pw.println("<td>" + data[6] + "</td>"); // Sat
		pw.println("</tr>");
		}
		pw.println("</tbody>");
		pw.println("</table>");
		pw.println("</body>");
		pw.println("</html>");
	}
}

insert image description here
Questions 1, 2, 3 are not solved, there are also problems with sorting

        int index = startWeek[month-1];
		for( int i = 1; i <= lastDay[month-1];i++ ) {
    
    

			if (month == 5 && i == 6) {
    
    
			row [0] = i + "<span style='color:gold;'>★</span>" ;
			}else {
    
    
			row[0] = i + "";
		}

			row[1] = dayOfWeek[index];
			list.add(row.clone());
			index++;
				if (index>6) {
    
    
				index =0;
				}
			}

insert image description here

Guess you like

Origin blog.csdn.net/weixin_51519327/article/details/113066213