Skip to content

Commit 8eac57f

Browse files
authored
words of the book of this prophecy
And if any man shall take away from the words of the book of this prophecy, God shall take away his part out of the book of life, and out of the holy city, and from the things which are written in this book. (Revelation 22:19)
1 parent 40aeadf commit 8eac57f

1 file changed

Lines changed: 47 additions & 0 deletions

File tree

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
2+
//And if any man shall take away from the words of the book of this prophecy, God shall take away his part out of the book of life, and out of the holy city, and from the things which are written in this book. (Revelation 22:19)
3+
4+
package com.javarush.task.task29.task2904;
5+
6+
/*
7+
Особенности автобоксинга
8+
*/
9+
public class Solution {
10+
private Integer[] array = new Integer[]{1, 2, 3, 4};
11+
12+
public static void main(String[] args) {
13+
Number value1 = new Solution().getValueByIndex(5); //-1.0, class java.lang.Double expected
14+
Number value2 = new Solution().getValueByIndex(2); //3, class java.lang.Integer expected
15+
16+
System.out.println(value1 + ", " + value1.getClass().toString());
17+
System.out.println(value2 + ", " + value2.getClass().toString());
18+
}
19+
20+
Number getValueByIndex(int index) {
21+
22+
if (index >= 0 && index < array.length) {return array[index];}
23+
else {return new Double(-1);}
24+
}
25+
}
26+
27+
/*
28+
Особенности автобоксинга
29+
30+
Исправь ошибку в методе getValueByIndex.
31+
32+
Читай доп. статью про особенности автобоксинга.
33+
34+
35+
36+
37+
38+
Требования:
39+
40+
1. Метод getValueByIndex должен возвращать объект типа Integer из массива array, если элемент с индексом index есть в массиве.
41+
42+
2. Метод getValueByIndex должен возвращать объект типа Double, равный -1, если в массиве array нет элемента с индексом index.
43+
44+
3. Метод main не изменять.
45+
46+
4. Программа должна вывести две строки: "-1.0, class java.lang.Double" и "3, class java.lang.Integer".
47+
*/

0 commit comments

Comments
 (0)