I am getting the error
"Exception in thread "main" java.util.InputMismatchException at java.util.Scanner.throwFor(Scanner.java:909) at java.util.Scanner.next(Scanner.java:1530) at java.util.Scanner.nextInt(Scanner.java:2160) at java.util.Scanner.nextInt(Scanner.java:2119) at SearchArray.main(SearchArray.java:10)"
when I have this code running. Can anyone tell me what I am doing wrong?
import java.util.Scanner;
public class SearchArray {
public static void main (String args[]){
//imput array size
//imput array digits
//imput element to search for
Scanner scan = new Scanner(System.in);
int size = scan.nextInt();
double array[] = new double[size];
for(int i = 0; i <= array.length-1; i++){
array[i] = scan.nextDouble();
}
double digit = scan.nextDouble();
boolean bool = findElement(array,digit);
if(bool == true){
System.out.println(digit + " was found in the array");
}else if(bool == false){
System.out.println(digit + " was NOT found in the array");
}
}
public static boolean findElement(double[] array, double digit){
boolean bool = false;
//accepts double array, double & returns boolean
//check if numnber entered is in the array
for(int i = 0; i <= array.length-1; i++){
if(array[i] == digit){
bool = true;
}else{
bool = false;
}
}
return bool;
}
}