A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

lmr1096200234

中级黑马

  • 黑马币:-26

  • 帖子:121

  • 精华:0

import java.util.Scanner;public class Test_Rili_Correct {public static void main( String[] args ) {String[] wd= { "日", "一", "二", "三", "四", "五", "六" };Scanner s = new Scanner(System.in);P("请输入要查询的年份:");int y = s.nextInt();P("请输入月份:");int m = s.nextInt();if(y < 1990 || y > 2016) {P("不在查询范围只内!");return;}GregorianCalendar g = new GregorianCalendar( y, m-1, 1 );P( "\n星期\t" );for ( int j = 0; j < wd.length; ++j )P( wd[j] + "\t" );P();for ( int j = 0; j < g.get( Calendar.DAY_OF_WEEK ); ++j )P( "\t" );int thisMonth = g.get( Calendar.MONTH );for ( int j = 1; j <= 31; ++j ) {int d = g.get( Calendar.DAY_OF_MONTH );P( d + "\t" );if ( g.get( Calendar.DAY_OF_WEEK ) == 7 ) {P("\n\t");}g.add( Calendar.DAY_OF_YEAR, 1 );if ( g.get( Calendar.MONDAY ) != thisMonth ) {P("\n\n");break;}}}static void P( String s ){System.out.print( s );}static void P(){System.out.println();}}





1 个回复

倒序浏览
  1. import java.util.*;

  2. public class Test_Rili_Correct {
  3. public static void main( String[] args ) {
  4. String[] wd= { "日", "一", "二", "三", "四", "五", "六" };
  5. Scanner s = new Scanner(System.in);
  6. P("请输入要查询的年份:");
  7. int y = s.nextInt();
  8. P("请输入月份:");
  9. int m = s.nextInt();
  10. if(y < 1990 || y > 2016) {
  11. P("不在查询范围只内!");
  12. return;
  13. }

  14. GregorianCalendar g = new GregorianCalendar( y, m-1, 1 );

  15. P( "\n星期\t" );
  16. for ( int j = 0; j < wd.length; ++j )
  17. P( wd[j] + "\t" );
  18. P();
  19. for ( int j = 0; j < g.get( Calendar.DAY_OF_WEEK ); ++j )
  20. P( "\t" );
  21. int thisMonth = g.get( Calendar.MONTH );
  22. for ( int j = 1; j <= 31; ++j ) {
  23. int d = g.get( Calendar.DAY_OF_MONTH );
  24. P( d + "\t" );
  25. if ( g.get( Calendar.DAY_OF_WEEK ) == 7 ) {
  26. P("\n\t");
  27. }
  28. g.add( Calendar.DAY_OF_YEAR, 1 );
  29. if ( g.get( Calendar.MONDAY ) != thisMonth ) {
  30. P("\n\n");
  31. break;
  32. }
  33. }
  34. }

  35. static void P( String s )
  36. {
  37. System.out.print( s );
  38. }
  39. static void P()
  40. {
  41. System.out.println();
  42. }
  43. }
复制代码
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 加入黑马