回答編集履歴
5
画像リンクの貼り直し
answer
CHANGED
@@ -100,7 +100,7 @@
|
|
100
100
|
```
|
101
101
|
---
|
102
102
|
### 出力結果
|
103
|
-

|
104
104
|
|
105
105
|
---
|
106
106
|
### 追加修正しました
|
4
間違いがあったので追加修正しました
answer
CHANGED
@@ -12,14 +12,23 @@
|
|
12
12
|
//・例外処理、うるう年判定、ツェラーの公式は使わない。
|
13
13
|
//
|
14
14
|
//・クラス分けして、メインメソッドから呼び出す方式。
|
15
|
-
public class memo201 {
|
16
15
|
|
17
16
|
public static void main(String[] args) {
|
18
17
|
|
18
|
+
//1月から12月のカレンダーを表示する
|
19
|
+
for (int i = 1; i <= 12; i++) {
|
19
|
-
|
20
|
+
func(i);
|
20
|
-
|
21
|
+
if (i < 12) {
|
22
|
+
//毎月行端と月の区切りで計2行改行
|
23
|
+
System.out.println();
|
24
|
+
System.out.println();
|
25
|
+
}
|
26
|
+
}
|
21
27
|
}
|
22
28
|
|
29
|
+
|
30
|
+
```
|
31
|
+
```java
|
23
32
|
//※条件1月1日が日曜日から合計日数で求める
|
24
33
|
//month月1日の曜日を0-6の数値で返す
|
25
34
|
public static int youbi(int month) {
|
@@ -42,14 +51,13 @@
|
|
42
51
|
return sum % 7;
|
43
52
|
}
|
44
53
|
|
54
|
+
```
|
55
|
+
```java
|
45
|
-
//
|
56
|
+
//month月のカレンダーを出力する
|
46
57
|
public static void func(int month) {
|
47
58
|
|
48
|
-
//month月1日の曜日=スペースの数になる
|
49
|
-
//youbi(month);
|
50
|
-
|
51
59
|
String[] Week = { "日", "月", "火", "水", "木", "金", "土" };
|
52
|
-
|
60
|
+
|
53
61
|
//月の表示
|
54
62
|
System.out.println(month + "月");
|
55
63
|
|
@@ -58,9 +66,9 @@
|
|
58
66
|
System.out.print(i);
|
59
67
|
System.out.println();
|
60
68
|
|
61
|
-
//1日の曜日をyoubiメソッドから求める
|
69
|
+
//month月1日の曜日をyoubiメソッドから求める
|
62
|
-
//
|
70
|
+
//youbiメソッドで得た値分マイナスからスタートさせ月初の曜日をずらす
|
63
|
-
//
|
71
|
+
//その後は月初から月末までの日を土曜日で折り返して出力させる
|
64
72
|
int count = 0;
|
65
73
|
for (int i = 1 - youbi(month); i <= 31; i++) {
|
66
74
|
count++;
|
@@ -68,14 +76,33 @@
|
|
68
76
|
System.out.print(" ");
|
69
77
|
continue;
|
70
78
|
}
|
79
|
+
//2月は28日で終了
|
80
|
+
if (month == 2) {
|
81
|
+
if (i >= 29) {
|
82
|
+
continue;
|
83
|
+
}
|
84
|
+
//4月6月9月11月は30日で終了
|
85
|
+
} else if (month == 4 || month == 6 || month == 9 || month == 11) {
|
86
|
+
if (i >= 31) {
|
87
|
+
continue;
|
88
|
+
}
|
89
|
+
}
|
90
|
+
//その他は31日までで終了
|
91
|
+
|
92
|
+
//日付を出力
|
71
93
|
System.out.printf("%02d", i);
|
72
94
|
|
95
|
+
//月初の空白を含む7日毎に(土曜日で)改行
|
73
|
-
if (count % 7 == 0)
|
96
|
+
if (count % 7 == 0)
|
74
97
|
System.out.println();
|
75
98
|
}
|
76
99
|
}
|
77
|
-
}
|
78
100
|
```
|
79
101
|
---
|
80
102
|
### 出力結果
|
81
|
-

|
104
|
+
|
105
|
+
---
|
106
|
+
### 追加修正しました
|
107
|
+
1-12月までの出力(main()のfor文のi=1を変えれば月指定出来ます)
|
108
|
+
月末日の処理が間違っていたので修正しました
|
3
未使用配列削除と説明コメントの追加修正
answer
CHANGED
@@ -45,10 +45,10 @@
|
|
45
45
|
//
|
46
46
|
public static void func(int month) {
|
47
47
|
|
48
|
-
|
48
|
+
//month月1日の曜日=スペースの数になる
|
49
|
+
//youbi(month);
|
49
50
|
|
50
51
|
String[] Week = { "日", "月", "火", "水", "木", "金", "土" };
|
51
|
-
int[][] c = new int[6][7];
|
52
52
|
|
53
53
|
//月の表示
|
54
54
|
System.out.println(month + "月");
|
@@ -70,7 +70,7 @@
|
|
70
70
|
}
|
71
71
|
System.out.printf("%02d", i);
|
72
72
|
|
73
|
-
if (count % 7 == 0)
|
73
|
+
if (count % 7 == 0) //週末で折り返して次の週へ
|
74
74
|
System.out.println();
|
75
75
|
}
|
76
76
|
}
|
2
画像リンクの貼り直し
answer
CHANGED
@@ -75,4 +75,7 @@
|
|
75
75
|
}
|
76
76
|
}
|
77
77
|
}
|
78
|
-
```
|
78
|
+
```
|
79
|
+
---
|
80
|
+
### 出力結果
|
81
|
+

|
1
画像のリンク削除とコメントの訂正
answer
CHANGED
@@ -1,9 +1,5 @@
|
|
1
1
|
```java
|
2
2
|
|
3
|
-
出力結果
|
4
|
-

|
5
|
-
|
6
|
-
|
7
3
|
// 課題
|
8
4
|
//・Calendarクラスや一切のimportの使用禁止。
|
9
5
|
//
|
@@ -64,7 +60,7 @@
|
|
64
60
|
|
65
61
|
//1日の曜日をyoubiメソッドから求める
|
66
62
|
//曜日分マイナスからスタートさせることで曜日をずらす
|
67
|
-
//曜日
|
63
|
+
//曜日をずらしたら月初から月末までの日を出力
|
68
64
|
int count = 0;
|
69
65
|
for (int i = 1 - youbi(month); i <= 31; i++) {
|
70
66
|
count++;
|