回答編集履歴

1

見直しキャンペーン中

2023/07/29 05:28

投稿

TN8001
TN8001

スコア9326

test CHANGED
@@ -1,109 +1,69 @@
1
1
  削除申請したぐらいですから見ていないんでしょうが、カレンダー表示自体はありがちですので回答しておきます。
2
-
3
-
4
2
 
5
3
  配列に入れる意味は感じませんが、質問タイトルに入っているため使用しました(無駄なクラスはバッサリカット)
6
4
 
7
-
8
-
9
5
  ```Java
10
-
11
6
  import java.util.Calendar;
12
-
13
7
  import java.util.Scanner;
14
8
 
15
-
16
-
17
9
  public class Sample {
18
-
19
10
  public static void main(String[] args) {
20
-
21
11
  Scanner sc = new Scanner(System.in);
22
12
 
23
-
24
-
25
13
  System.out.println("西暦年を入れてください");
26
-
27
14
  int year = Integer.parseInt(sc.nextLine());
28
15
 
29
-
30
-
31
16
  System.out.println("月を入力してください");
32
-
33
17
  int month = Integer.parseInt(sc.nextLine());
34
18
 
35
-
36
-
37
19
  Calendar cal = Calendar.getInstance();
38
-
39
20
  cal.set(Calendar.YEAR, year);
40
-
41
21
  cal.set(Calendar.MONTH, month - 1);
42
-
43
22
  cal.set(Calendar.DATE, 1);
44
23
 
45
-
46
-
47
24
  int wk = cal.get(Calendar.DAY_OF_WEEK);
48
-
49
25
  int tuki_max = cal.getActualMaximum(Calendar.DATE);
50
26
 
51
-
52
-
53
27
  int[][] cal_tbl = new int[6][7];
54
-
55
28
  int cnt_day = 1;
56
29
 
57
-
58
-
59
30
  for (int i = 0; i < 6; i++) {
60
-
61
31
  for (int j = 0; j < 7; j++) {
62
-
63
32
  if (i == 0 && j < wk - 1) {
64
-
65
33
  continue;
66
-
67
34
  }
68
35
 
69
-
70
-
71
36
  if (cnt_day <= tuki_max) {
72
-
73
37
  cal_tbl[i][j] = cnt_day++;
74
-
75
38
  }
76
-
77
39
  }
78
-
79
40
  }
80
41
 
81
-
82
-
83
42
  System.out.println("日\t月\t火\t水\t木\t金\t土");
84
-
85
43
  for (int[] anInt : cal_tbl) {
86
-
87
44
  for (int i : anInt) {
88
-
89
45
  if (i == 0) {
90
-
91
46
  System.out.print(" \t");
92
-
93
47
  } else {
94
-
95
48
  System.out.printf("%2d\t", i);
96
-
97
49
  }
98
-
99
50
  }
100
-
101
51
  System.out.println(); // ココ
102
-
103
52
  }
104
-
105
53
  }
106
-
107
54
  }
55
+ ```
108
56
 
109
57
  ```
58
+ 西暦年を入れてください
59
+ 2021
60
+ 月を入力してください
61
+ 9
62
+ 日 月 火 水 木 金 土
63
+ 1 2 3 4
64
+ 5 6 7 8 9 10 11
65
+ 12 13 14 15 16 17 18
66
+ 19 20 21 22 23 24 25
67
+ 26 27 28 29 30
68
+
69
+ ```