Created
November 3, 2015 14:46
-
-
Save edinak1/76fa1ea8bcabe1ab2a3f to your computer and use it in GitHub Desktop.
This file contains 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 test; | |
public class Finde { | |
public static void main(String[] args) { | |
double[] numbers={1.0,7.0,9.0}; | |
double[] numbers1={}; | |
double[] numbers2={-1.0,7.0,9.2}; | |
double el=9.2; | |
print(findElement(numbers,el)); | |
print(findElement(numbers1,el)); | |
print(findElement(numbers2,el)); | |
} | |
static int findElement(double[]numbers,double el) | |
{ | |
if(numbers==null || numbers.length==0) | |
return -2; | |
for(int i=0;i<numbers.length;i++) | |
{ | |
if(numbers[i]==el) | |
return i; | |
} | |
return-1; | |
} | |
static void print(int number) | |
{ | |
if(number==-2) | |
System.out.println("Arrays not found!"); | |
else if(number==-1) | |
System.out.println("Element not found!"); | |
else | |
System.out.println("Number of element = "+number); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment