如何根据用户输入来打印日历?

时间:2019-02-28 19:43:02

标签: java calendar

对于我的课程,我想让它询问用户一年以及1月1日是星期几。有了这些信息,我希望它可以打印一月到十二月的日历。我有它,因此它可以接受输入年份和日期(现在什么日子都不做),然后在打印后重新开始并询问。我也试图使用嵌套循环。 (哨兵是任务的后续要求,我知道该怎么做)

我不知道如何根据用户提供的信息来打印日历。

`
import java.util.Scanner;

public class Calendar 
{

 public static void main(String[] args) 
{
     Scanner input = new Scanner(System.in);
     int sentinel = 0;

     System.out.println("What year?");
     String year = input.nextLine();
     System.out.println("What day of the week is January 1st?");
     String dow = input.nextLine();
     int day = 1;
     System.out.println("\n");
     System.out.printf("%1s  %2s  %2s  %2s  %2s  %2s  %2s", "Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday");


     while (sentinel != -1)
     {
          System.out.println("\n\n What year?");
          year = input.nextLine();
          System.out.println("What day of the week is January 1st?");
          dow = input.nextLine();
          day = 1;

          System.out.printf("%15s  %1s  %2s", "January", Day, Year);
          System.out.println("\n");
          System.out.printf("%1s  %2s  %2s  %2s  %2s %2s  %2s", "Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday");
     }
   }
}`

0 个答案:

没有答案