質問編集履歴
3
言語名を入力するところとソースコードのあたりを修正いたしました。
test
CHANGED
File without changes
|
test
CHANGED
@@ -24,9 +24,7 @@
|
|
24
24
|
|
25
25
|
|
26
26
|
|
27
|
-
```Java
|
27
|
+
```Java
|
28
|
-
|
29
|
-
ソースコード
|
30
28
|
|
31
29
|
import java.util.Scanner;
|
32
30
|
|
2
該当のソースの下から修正したソースコードの間のコードを削除いたしました。
test
CHANGED
File without changes
|
test
CHANGED
@@ -24,6 +24,60 @@
|
|
24
24
|
|
25
25
|
|
26
26
|
|
27
|
+
```Javaここに言語名を入力
|
28
|
+
|
29
|
+
ソースコード
|
30
|
+
|
31
|
+
import java.util.Scanner;
|
32
|
+
|
33
|
+
|
34
|
+
|
35
|
+
class YMD {
|
36
|
+
|
37
|
+
int y; // 西暦年
|
38
|
+
|
39
|
+
int m; // 月(1~12)
|
40
|
+
|
41
|
+
int d; // 日(1~31)
|
42
|
+
|
43
|
+
|
44
|
+
|
45
|
+
//--- 各月の日数 ---//
|
46
|
+
|
47
|
+
static int[][] mdays = {
|
48
|
+
|
49
|
+
{31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}, // 平年
|
50
|
+
|
51
|
+
{31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}, // 閏年
|
52
|
+
|
53
|
+
};
|
54
|
+
|
55
|
+
|
56
|
+
|
57
|
+
//--- 西暦year年は閏年か(閏年:1/平年:0) ---//
|
58
|
+
|
59
|
+
static int isLeap(int year) {
|
60
|
+
|
61
|
+
return (year % 4 == 0 && year % 100 != 0 || year % 400 == 0) ? 1 : 0;
|
62
|
+
|
63
|
+
}
|
64
|
+
|
65
|
+
|
66
|
+
|
67
|
+
//--- コンストラクタ(与えられた日付に設定)---//
|
68
|
+
|
69
|
+
YMD(int y, int m, int d) {
|
70
|
+
|
71
|
+
this.y = y;
|
72
|
+
|
73
|
+
this.m = m;
|
74
|
+
|
75
|
+
this.d = d;
|
76
|
+
|
77
|
+
}
|
78
|
+
|
79
|
+
|
80
|
+
|
27
81
|
//--- n日後の日付を返す ---//
|
28
82
|
|
29
83
|
YMD after(int n) {
|
@@ -96,136 +150,6 @@
|
|
96
150
|
|
97
151
|
|
98
152
|
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
```Javaここに言語名を入力
|
104
|
-
|
105
|
-
ソースコード
|
106
|
-
|
107
|
-
import java.util.Scanner;
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
class YMD {
|
112
|
-
|
113
|
-
int y; // 西暦年
|
114
|
-
|
115
|
-
int m; // 月(1~12)
|
116
|
-
|
117
|
-
int d; // 日(1~31)
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
//--- 各月の日数 ---//
|
122
|
-
|
123
|
-
static int[][] mdays = {
|
124
|
-
|
125
|
-
{31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}, // 平年
|
126
|
-
|
127
|
-
{31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}, // 閏年
|
128
|
-
|
129
|
-
};
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
//--- 西暦year年は閏年か(閏年:1/平年:0) ---//
|
134
|
-
|
135
|
-
static int isLeap(int year) {
|
136
|
-
|
137
|
-
return (year % 4 == 0 && year % 100 != 0 || year % 400 == 0) ? 1 : 0;
|
138
|
-
|
139
|
-
}
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
//--- コンストラクタ(与えられた日付に設定)---//
|
144
|
-
|
145
|
-
YMD(int y, int m, int d) {
|
146
|
-
|
147
|
-
this.y = y;
|
148
|
-
|
149
|
-
this.m = m;
|
150
|
-
|
151
|
-
this.d = d;
|
152
|
-
|
153
|
-
}
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
//--- n日後の日付を返す ---//
|
158
|
-
|
159
|
-
YMD after(int n) {
|
160
|
-
|
161
|
-
YMD temp = new YMD(this.y, this.m, this.d);
|
162
|
-
|
163
|
-
if (n < 0)
|
164
|
-
|
165
|
-
return (before(-n));
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
temp.d += n;
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
while (temp.d > mdays[isLeap(temp.y)][temp.m - 1]) {
|
174
|
-
|
175
|
-
temp.d -= mdays[isLeap(temp.y)][temp.m - 1];
|
176
|
-
|
177
|
-
if (++temp.m > 12) {
|
178
|
-
|
179
|
-
temp.y++;
|
180
|
-
|
181
|
-
temp.m = 1;
|
182
|
-
|
183
|
-
}
|
184
|
-
|
185
|
-
}
|
186
|
-
|
187
|
-
return temp;
|
188
|
-
|
189
|
-
}
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
//--- n日前の日付を返す ---//
|
194
|
-
|
195
|
-
YMD before(int n) {
|
196
|
-
|
197
|
-
YMD temp = new YMD(this.y, this.m, this.d);
|
198
|
-
|
199
|
-
if (n < 0)
|
200
|
-
|
201
|
-
return (after(-n));
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
temp.d -= n;
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
while (temp.d < 1) {
|
210
|
-
|
211
|
-
if (--temp.m < 1) {
|
212
|
-
|
213
|
-
temp.y--;
|
214
|
-
|
215
|
-
temp.m = 12;
|
216
|
-
|
217
|
-
}
|
218
|
-
|
219
|
-
temp.d += mdays[isLeap(temp.y)][temp.m - 1];
|
220
|
-
|
221
|
-
}
|
222
|
-
|
223
|
-
return temp;
|
224
|
-
|
225
|
-
}
|
226
|
-
|
227
|
-
|
228
|
-
|
229
153
|
public static void main(String[] args) {
|
230
154
|
|
231
155
|
Scanner stdIn = new Scanner(System.in);
|
1
言語名を記入し、ソースコードを、、、の中に書きました。
test
CHANGED
File without changes
|
test
CHANGED
@@ -100,172 +100,172 @@
|
|
100
100
|
|
101
101
|
|
102
102
|
|
103
|
-
```ここに言語名を入力
|
103
|
+
```Javaここに言語名を入力
|
104
104
|
|
105
105
|
ソースコード
|
106
106
|
|
107
|
+
import java.util.Scanner;
|
108
|
+
|
109
|
+
|
110
|
+
|
111
|
+
class YMD {
|
112
|
+
|
113
|
+
int y; // 西暦年
|
114
|
+
|
115
|
+
int m; // 月(1~12)
|
116
|
+
|
117
|
+
int d; // 日(1~31)
|
118
|
+
|
119
|
+
|
120
|
+
|
121
|
+
//--- 各月の日数 ---//
|
122
|
+
|
123
|
+
static int[][] mdays = {
|
124
|
+
|
125
|
+
{31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}, // 平年
|
126
|
+
|
127
|
+
{31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}, // 閏年
|
128
|
+
|
129
|
+
};
|
130
|
+
|
131
|
+
|
132
|
+
|
133
|
+
//--- 西暦year年は閏年か(閏年:1/平年:0) ---//
|
134
|
+
|
135
|
+
static int isLeap(int year) {
|
136
|
+
|
137
|
+
return (year % 4 == 0 && year % 100 != 0 || year % 400 == 0) ? 1 : 0;
|
138
|
+
|
139
|
+
}
|
140
|
+
|
141
|
+
|
142
|
+
|
143
|
+
//--- コンストラクタ(与えられた日付に設定)---//
|
144
|
+
|
145
|
+
YMD(int y, int m, int d) {
|
146
|
+
|
147
|
+
this.y = y;
|
148
|
+
|
149
|
+
this.m = m;
|
150
|
+
|
151
|
+
this.d = d;
|
152
|
+
|
153
|
+
}
|
154
|
+
|
155
|
+
|
156
|
+
|
157
|
+
//--- n日後の日付を返す ---//
|
158
|
+
|
159
|
+
YMD after(int n) {
|
160
|
+
|
161
|
+
YMD temp = new YMD(this.y, this.m, this.d);
|
162
|
+
|
163
|
+
if (n < 0)
|
164
|
+
|
165
|
+
return (before(-n));
|
166
|
+
|
167
|
+
|
168
|
+
|
169
|
+
temp.d += n;
|
170
|
+
|
171
|
+
|
172
|
+
|
173
|
+
while (temp.d > mdays[isLeap(temp.y)][temp.m - 1]) {
|
174
|
+
|
175
|
+
temp.d -= mdays[isLeap(temp.y)][temp.m - 1];
|
176
|
+
|
177
|
+
if (++temp.m > 12) {
|
178
|
+
|
179
|
+
temp.y++;
|
180
|
+
|
181
|
+
temp.m = 1;
|
182
|
+
|
183
|
+
}
|
184
|
+
|
185
|
+
}
|
186
|
+
|
187
|
+
return temp;
|
188
|
+
|
189
|
+
}
|
190
|
+
|
191
|
+
|
192
|
+
|
193
|
+
//--- n日前の日付を返す ---//
|
194
|
+
|
195
|
+
YMD before(int n) {
|
196
|
+
|
197
|
+
YMD temp = new YMD(this.y, this.m, this.d);
|
198
|
+
|
199
|
+
if (n < 0)
|
200
|
+
|
201
|
+
return (after(-n));
|
202
|
+
|
203
|
+
|
204
|
+
|
205
|
+
temp.d -= n;
|
206
|
+
|
207
|
+
|
208
|
+
|
209
|
+
while (temp.d < 1) {
|
210
|
+
|
211
|
+
if (--temp.m < 1) {
|
212
|
+
|
213
|
+
temp.y--;
|
214
|
+
|
215
|
+
temp.m = 12;
|
216
|
+
|
217
|
+
}
|
218
|
+
|
219
|
+
temp.d += mdays[isLeap(temp.y)][temp.m - 1];
|
220
|
+
|
221
|
+
}
|
222
|
+
|
223
|
+
return temp;
|
224
|
+
|
225
|
+
}
|
226
|
+
|
227
|
+
|
228
|
+
|
229
|
+
public static void main(String[] args) {
|
230
|
+
|
231
|
+
Scanner stdIn = new Scanner(System.in);
|
232
|
+
|
233
|
+
|
234
|
+
|
235
|
+
System.out.print("日付を入力してください。\n");
|
236
|
+
|
237
|
+
System.out.print("年:"); int y = stdIn.nextInt();
|
238
|
+
|
239
|
+
System.out.print("月:"); int m = stdIn.nextInt();
|
240
|
+
|
241
|
+
System.out.print("日:"); int d = stdIn.nextInt();
|
242
|
+
|
243
|
+
YMD date = new YMD(y, m, d);
|
244
|
+
|
245
|
+
|
246
|
+
|
247
|
+
System.out.print("何日前/後の日付を求めますか:");
|
248
|
+
|
249
|
+
int n = stdIn.nextInt();
|
250
|
+
|
251
|
+
|
252
|
+
|
253
|
+
YMD d1 = date.after(n);
|
254
|
+
|
255
|
+
System.out.printf("%d日後の日付は%d年%d月%d日です。\n", n, d1.y, d1.m, d1.d);
|
256
|
+
|
257
|
+
|
258
|
+
|
259
|
+
YMD d2 = date.before(n);
|
260
|
+
|
261
|
+
System.out.printf("%d日前の日付は%d年%d月%d日です。\n", n, d2.y, d2.m, d2.d);
|
262
|
+
|
263
|
+
}
|
264
|
+
|
265
|
+
}
|
266
|
+
|
107
267
|
```
|
108
268
|
|
109
|
-
import java.util.Scanner;
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
class YMD {
|
114
|
-
|
115
|
-
int y; // 西暦年
|
116
|
-
|
117
|
-
int m; // 月(1~12)
|
118
|
-
|
119
|
-
int d; // 日(1~31)
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
//--- 各月の日数 ---//
|
124
|
-
|
125
|
-
static int[][] mdays = {
|
126
|
-
|
127
|
-
{31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}, // 平年
|
128
|
-
|
129
|
-
{31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}, // 閏年
|
130
|
-
|
131
|
-
};
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
//--- 西暦year年は閏年か(閏年:1/平年:0) ---//
|
136
|
-
|
137
|
-
static int isLeap(int year) {
|
138
|
-
|
139
|
-
return (year % 4 == 0 && year % 100 != 0 || year % 400 == 0) ? 1 : 0;
|
140
|
-
|
141
|
-
}
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
//--- コンストラクタ(与えられた日付に設定)---//
|
146
|
-
|
147
|
-
YMD(int y, int m, int d) {
|
148
|
-
|
149
|
-
this.y = y;
|
150
|
-
|
151
|
-
this.m = m;
|
152
|
-
|
153
|
-
this.d = d;
|
154
|
-
|
155
|
-
}
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
//--- n日後の日付を返す ---//
|
160
|
-
|
161
|
-
YMD after(int n) {
|
162
|
-
|
163
|
-
YMD temp = new YMD(this.y, this.m, this.d);
|
164
|
-
|
165
|
-
if (n < 0)
|
166
|
-
|
167
|
-
return (before(-n));
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
temp.d += n;
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
while (temp.d > mdays[isLeap(temp.y)][temp.m - 1]) {
|
176
|
-
|
177
|
-
temp.d -= mdays[isLeap(temp.y)][temp.m - 1];
|
178
|
-
|
179
|
-
if (++temp.m > 12) {
|
180
|
-
|
181
|
-
temp.y++;
|
182
|
-
|
183
|
-
temp.m = 1;
|
184
|
-
|
185
|
-
}
|
186
|
-
|
187
|
-
}
|
188
|
-
|
189
|
-
return temp;
|
190
|
-
|
191
|
-
}
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
//--- n日前の日付を返す ---//
|
196
|
-
|
197
|
-
YMD before(int n) {
|
198
|
-
|
199
|
-
YMD temp = new YMD(this.y, this.m, this.d);
|
200
|
-
|
201
|
-
if (n < 0)
|
202
|
-
|
203
|
-
return (after(-n));
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
temp.d -= n;
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
while (temp.d < 1) {
|
212
|
-
|
213
|
-
if (--temp.m < 1) {
|
214
|
-
|
215
|
-
temp.y--;
|
216
|
-
|
217
|
-
temp.m = 12;
|
218
|
-
|
219
|
-
}
|
220
|
-
|
221
|
-
temp.d += mdays[isLeap(temp.y)][temp.m - 1];
|
222
|
-
|
223
|
-
}
|
224
|
-
|
225
|
-
return temp;
|
226
|
-
|
227
|
-
}
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
public static void main(String[] args) {
|
232
|
-
|
233
|
-
Scanner stdIn = new Scanner(System.in);
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
System.out.print("日付を入力してください。\n");
|
238
|
-
|
239
|
-
System.out.print("年:"); int y = stdIn.nextInt();
|
240
|
-
|
241
|
-
System.out.print("月:"); int m = stdIn.nextInt();
|
242
|
-
|
243
|
-
System.out.print("日:"); int d = stdIn.nextInt();
|
244
|
-
|
245
|
-
YMD date = new YMD(y, m, d);
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
System.out.print("何日前/後の日付を求めますか:");
|
250
|
-
|
251
|
-
int n = stdIn.nextInt();
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
YMD d1 = date.after(n);
|
256
|
-
|
257
|
-
System.out.printf("%d日後の日付は%d年%d月%d日です。\n", n, d1.y, d1.m, d1.d);
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
YMD d2 = date.before(n);
|
262
|
-
|
263
|
-
System.out.printf("%d日前の日付は%d年%d月%d日です。\n", n, d2.y, d2.m, d2.d);
|
264
|
-
|
265
|
-
}
|
266
|
-
|
267
|
-
}
|
268
|
-
|
269
269
|
|
270
270
|
|
271
271
|
|