Skip to content

Instantly share code, notes, and snippets.

@edinak1
Created November 3, 2015 14:49
Show Gist options
  • Save edinak1/f99c97d2d86dc2762a41 to your computer and use it in GitHub Desktop.
Save edinak1/f99c97d2d86dc2762a41 to your computer and use it in GitHub Desktop.
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