質問編集履歴
3
日本語の修正
title
CHANGED
File without changes
|
body
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
### 前提・実現したいこと
|
2
|
-
|
2
|
+
関数next内の前半のfor文と後半の入れ子になっているfor文を一つの入れ子になっているfor文にまとめたいです。
|
3
3
|
なんかかっこ悪いのでスマートな書き方があったら教えてください。
|
4
4
|
hyoはvかけるvの二次元配列
|
5
5
|
now_gyo,now_retuはグローバル変数
|
2
コード全体を乗せた
title
CHANGED
File without changes
|
body
CHANGED
@@ -16,19 +16,41 @@
|
|
16
16
|
|
17
17
|
```java
|
18
18
|
|
19
|
+
import java.util.Arrays;
|
20
|
+
|
21
|
+
public class hogehoge {
|
22
|
+
public static int now_gyo=1;
|
23
|
+
public static int now_retu=2;
|
24
|
+
public static int v=5;
|
25
|
+
public static void main(String[] args) {
|
26
|
+
next();
|
27
|
+
|
28
|
+
}
|
29
|
+
public static void next() {
|
30
|
+
|
31
|
+
int[][] hyo=new int[][]{
|
32
|
+
{0 ,-1, -1 , 5 ,-1},
|
33
|
+
{-1 , 0, -1 , 4 , 5},
|
34
|
+
{-1 ,-1, 0 , 2 ,-1},
|
35
|
+
{-1 ,-1, -1 , 0 ,-1},
|
36
|
+
{-1 ,-1, -1 ,-1 , 0}
|
37
|
+
};
|
19
|
-
|
38
|
+
for (int i = now_retu+1; i < v; i++) {
|
20
|
-
|
39
|
+
if(hyo[now_gyo][i]==-1){
|
21
|
-
|
40
|
+
now_retu=i;
|
22
|
-
|
41
|
+
return;
|
23
|
-
|
42
|
+
}
|
24
|
-
|
43
|
+
}
|
25
|
-
|
44
|
+
for (int i = now_gyo+1; i < v; i++) {
|
26
|
-
|
45
|
+
for (int j = i+1; j < v; j++) {
|
27
|
-
|
46
|
+
if(hyo[i][j]==-1){
|
28
|
-
|
47
|
+
now_gyo=i;
|
29
|
-
|
48
|
+
now_retu=j;
|
30
|
-
|
49
|
+
return;
|
31
|
-
|
50
|
+
}
|
32
|
-
|
51
|
+
}
|
33
|
-
|
52
|
+
}
|
53
|
+
}
|
54
|
+
}
|
55
|
+
|
34
56
|
```
|
1
xをnow_gyo,yを now_retuに置換しました
title
CHANGED
File without changes
|
body
CHANGED
@@ -16,17 +16,17 @@
|
|
16
16
|
|
17
17
|
```java
|
18
18
|
|
19
|
-
for (int i =
|
19
|
+
for (int i = now_retu+1; i < v; i++) {
|
20
|
-
if(hyo[
|
20
|
+
if(hyo[now_gyo][i]==-1){
|
21
|
-
|
21
|
+
now_retu=i;
|
22
22
|
return;
|
23
23
|
}
|
24
24
|
}
|
25
|
-
for (int i =
|
25
|
+
for (int i = now_gyo+1; i < v; i++) {
|
26
26
|
for (int j = i+1; j < v; j++) {
|
27
27
|
if(hyo[i][j]==-1){
|
28
|
-
|
28
|
+
now_gyo=i;
|
29
|
-
|
29
|
+
now_retu=j;
|
30
30
|
return;
|
31
31
|
}
|
32
32
|
}
|