質問編集履歴

2

アドバイスを参考に構文を修正しました。

2023/05/23 15:10

投稿

JAVA-B1
JAVA-B1

スコア4

test CHANGED
File without changes
test CHANGED
@@ -15,18 +15,18 @@
15
15
  > java test2023 2023 9 14
16
16
  2023:9:14:Thu:(257/365)
17
17
 
18
+ > java test2023 2024 9 14
19
+ 2024:9:14:Tue:(514/365)
20
+
18
21
  実際
19
22
  > java test2023 2023 9 14
20
23
  2023:9:14:Thu:(257/365)
24
+
25
+ > java test2023 2024 9 14
21
- 2024:9:14:Tue:(514/365)
26
+ 2024:9:14:Thu:(257/365)
22
- 2025:9:14:Sun:(771/365)
23
- 2026:9:14:Fri:(1028/365)
24
27
 
25
28
  問題点1
26
- 指定した年数の情報だけ出したいのですが、23年~26年までの結果が1行で表示されます。
27
-
28
- 問題点2
29
- 数カウント年を越すごとに増えてしまます。
29
+ 2023→2024にしても曜日が計算されな
30
30
 
31
31
 
32
32
  ```
@@ -35,56 +35,30 @@
35
35
  ```Java
36
36
  class test2023{
37
37
  public static void main(String[] args){
38
-
39
38
  int i;
40
39
  int[] y ={0,2023,2024,2025,2026};
40
+ // jan feb mar apr may junjul aug sep oct nov dec
41
41
  int[] m ={0,31,28,31,30,31,30,31,31,30,31,30,31};
42
-
43
- //2023年は1日が日曜日なので、Sunが配列の1番目になるよう曜日を配置
42
+ //2023年は1日が日曜日なので、Sunが配列の1番目になるよう曜日を配置
44
- String[] week ={"Sat","Sun","Mon","Tue","Wed","Thu","Fri"};
43
+ String[] week ={"sat","Sun","Mon","Tue","Wed","Thu","Fri"};
45
44
  int year =Integer.parseInt(args[0]);//年
46
45
  int month =Integer.parseInt(args[1]);//月
47
46
  int day =Integer.parseInt(args[2]);//日
48
-
49
47
  int count =0;//年初からの日数
50
-
48
+
51
- //うるう年(2024)か、それ以外の年で場合分け
49
+ //うるう年を計算する
52
- for(i=y1;i<=y2;i++){
50
+ for(i=2023;i<=year;i++){
53
51
  if(i%400 == 0 || i%4 == 0 && i%100 != 0){
54
52
  }
55
-
56
- //2023の場合
53
+
57
- if int year = 2023;
58
54
  for(i=1;i<month;i++){//前月までの日数を加える
59
- count =count + m[i];
55
+ count =count + m[i];
56
+ }
57
+ count =count + day;//今月までの日数を加える
58
+ System.out.println(year+":"+month+":"+day+":"+week[count%7]+":("+count+"/365)");
59
+ }
60
60
  }
61
- count =count + day;
62
- System.out.println(year+":"+month+":"+day+":"+week[count%7]+":("+count+"/365)");
63
- break;
64
- }
61
+ }
65
-
66
- //2025の場合
67
- int year = 2025
68
- count = 0
69
- for(i=1;i<month;i++){//前月までの日数を加える
70
- count =count + m[i];
71
- }
72
- count =count + day;
73
- System.out.println(year+":"+month+":"+day+":"+week[count%7+2]+":("+count+"/365)");
74
- break;
75
- }
76
- //うるう年のせいで、日が+1、曜日が+1される。
77
-
78
- //2026
79
- int year = 2026
80
- count = 0
81
- for(i=1;i<month;i++){//前月までの日数を加える
82
- count =count + m[i];
83
- }
84
- count =count + day;
85
- System.out.println(year+":"+month+":"+day+":"+week[count%7+2]+":("+count+"/365)");
86
- break;
87
- }
88
62
 
89
63
  ```
90
64
 

1

ソースコードの前後に```を追記しました

2023/05/23 12:58

投稿

JAVA-B1
JAVA-B1

スコア4

test CHANGED
File without changes
test CHANGED
@@ -32,7 +32,7 @@
32
32
  ```
33
33
 
34
34
  ### 該当のソースコード
35
-
35
+ ```Java
36
36
  class test2023{
37
37
  public static void main(String[] args){
38
38