java 控制台简单日历查看
Posted algorithmvcerhj
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了java 控制台简单日历查看相关的知识,希望对你有一定的参考价值。
先上代码:
import connection.FirstPanel; import java.util.Calendar; import java.util.Date; import java.util.Scanner; //为什么使用Date类了呢 因为Calendar类 国际化标准 public class Main { public static void main(String[] args) { Scanner sc = new Scanner (System.in); String[] English = {"一","二","三","四","五","六","日"}; String[] Month = {"一月","二月","三月","四月","五月","六月","七月","八月","九月","十月","十一月","十二月",}; while(sc.hasNext()){ int cc = 0; int year = sc.nextInt(); Calendar calendar = Calendar.getInstance(); for(int i = 0 ;i <12;i++){ System.out.println(Month[cc++]); for(int j = 0 ; j <English.length;j++){ System.out.printf("%3s",English[j]); } System.out.println(); calendar.clear(); calendar.set(Calendar.YEAR,year); calendar.set(Calendar.MONTH,i); int Month_Days = calendar.getActualMaximum(Calendar.DAY_OF_MONTH); int First_Day = calendar.get(Calendar.DAY_OF_WEEK)-1; int n =0; if (First_Day>0){ for(int k = 2 ; k<=First_Day ; k++){ n = First_Day-1; System.out.printf("%4s"," "); } } if(First_Day==0){ n = 6; for(int k = 1 ; k< 7 ;k++){ System.out.printf("%4s"," "); } } for (int k = 1 ;k<=Month_Days;k++){ System.out.printf("%3d ",k); n++; if(n%7==0){ System.out.println(); } } System.out.println(); } } } }
利用Java 中的 java.util.Calendar;(国际化标准日期类)给出的一些实例方法。
以上是关于java 控制台简单日历查看的主要内容,如果未能解决你的问题,请参考以下文章