回答編集履歴
2
java7の場合を追記
test
CHANGED
@@ -21,3 +21,51 @@
|
|
21
21
|
System.out.println(maxIndex);
|
22
22
|
|
23
23
|
```
|
24
|
+
|
25
|
+
|
26
|
+
|
27
|
+
~java7でしたらこんな感じですかね
|
28
|
+
|
29
|
+
|
30
|
+
|
31
|
+
```java
|
32
|
+
|
33
|
+
|
34
|
+
|
35
|
+
int[] a = new int[] { 1, 4, 2, 3, 4, 5 };
|
36
|
+
|
37
|
+
int[] b = new int[] { 2, 1, 5, 6, 7, 0 };
|
38
|
+
|
39
|
+
|
40
|
+
|
41
|
+
int maxIndex = 0;
|
42
|
+
|
43
|
+
int maxNum = 0;
|
44
|
+
|
45
|
+
|
46
|
+
|
47
|
+
for (int i = 0; i < a.length; i++) {
|
48
|
+
|
49
|
+
|
50
|
+
|
51
|
+
if (maxNum < a[i] + b[i]) {
|
52
|
+
|
53
|
+
maxNum = a[i] + b[i];
|
54
|
+
|
55
|
+
maxIndex = i + 1;
|
56
|
+
|
57
|
+
}
|
58
|
+
|
59
|
+
|
60
|
+
|
61
|
+
}
|
62
|
+
|
63
|
+
|
64
|
+
|
65
|
+
System.out.println(maxIndex);
|
66
|
+
|
67
|
+
|
68
|
+
|
69
|
+
}
|
70
|
+
|
71
|
+
```
|
1
質問の意図を勘違いしていたので修正しました。
test
CHANGED
@@ -10,12 +10,14 @@
|
|
10
10
|
|
11
11
|
|
12
12
|
|
13
|
-
int max
|
13
|
+
int maxIndex = IntStream.range(0, a.length).mapToObj(index -> index)
|
14
14
|
|
15
|
+
.sorted((index1, index2) -> (a[index2] + b[index2]) - (a[index1] + b[index1]))
|
16
|
+
|
15
|
-
.get
|
17
|
+
.findFirst().get();
|
16
18
|
|
17
19
|
|
18
20
|
|
19
|
-
System.out.println(max
|
21
|
+
System.out.println(maxIndex);
|
20
22
|
|
21
23
|
```
|