Created
January 7, 2016 17:33
-
-
Save Yur-ok/dffb7a5429bcf390a528 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package Lesson3.KeyPoint5; | |
import java.util.Arrays; | |
/** | |
* Created by Юрий on 08.01.2016. | |
*/ | |
public class FindElement { | |
public static void main(String[] args) { | |
double[] num = {2.2, 3.4, 2.1, 6.4, 6.4}; | |
System.out.println(findElement(num, 3.3)); | |
System.out.println(findElement(num, 3.4)); | |
System.out.println(findElement(num, 6.5)); | |
} | |
static int findElement(double[] numbers, double el) { | |
for (int i = 0; i < numbers.length - 1; i++) { | |
if (numbers[i] == el) { | |
return i; | |
} | |
} | |
return -1; | |
} | |
} |
liuiv15
commented
Jan 21, 2016
- если массив будет иметь значение null, то будет ошибка.
- если искомый элемент будет стоять на последней позиции, то результат будет -1. Это не верно.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment