Boa noite, estou em dúvida sobre o que está levando o meu programa a funcionar direito com os números 6, 8 e 9 mas não com 3 e o 4 no array.
O código juntamente com os resultados se encontra abaixo:
int v[] = {6,3,8,4,9};
System.out.println("Array:{6,3,8,4,9}");
Scanner keyboard = new Scanner(System.in);
System.out.println("Could you say the number you would like to remove?");
int answer = keyboard.nextInt();
int search = Arrays.binarySearch(v, answer);
System.out.println("Analyzing your number.....");
if(search>=0){
v[search] = 0;
for(int value: v){
System.out.print(value + " ");
}
System.out.println("Successfully removed!");
}else{
System.out.println("Sorry, but this number is not a component of this array.");
}
Resultado com sucesso: http://prntscr.com/dffjoi
Resultado sem sucesso: http://prntscr.com/dffjr5
Obrigado.