for (int i = 0; i < arr.length; i++) {
if (arr[i] == s) {
System.out.println("The index of " + s + " is " + i);
} else {
System.out.println("The entered element is not in the array");
}
}
Output:
Enter the Element:
656
The entered element is not in the array
The entered element is not in the array
The index of 656 is 2
The entered element is not in the array
The entered element is not in the array
Aucun commentaire:
Enregistrer un commentaire