Skip to content

Instantly share code, notes, and snippets.

@Yur-ok
Created January 7, 2016 17:33
Show Gist options
  • Select an option

  • Save Yur-ok/dffb7a5429bcf390a528 to your computer and use it in GitHub Desktop.

Select an option

Save Yur-ok/dffb7a5429bcf390a528 to your computer and use it in GitHub Desktop.
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
Copy link
Copy Markdown

liuiv15 commented Jan 21, 2016

  1. если массив будет иметь значение null, то будет ошибка.
  2. если искомый элемент будет стоять на последней позиции, то результат будет -1. Это не верно.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment