J
J
Java Developer2021-04-02 09:07:19
Java
Java Developer, 2021-04-02 09:07:19

How to check if an array of type int contains the number 5 for example?

public static void main(String[] args) {

int[] arrey={1,9,3,4,5};

Answer the question

In order to leave comments, you need to log in

3 answer(s)
S
Sergey Gornostaev, 2021-04-02
@Elxanjv_1

Obviously, bypass the array and compare all elements with the desired one.

V
Vasily Bannikov, 2021-04-02
@vabka

The answer is easily found by a search engine.
https://stackoverflow.com/questions/6171663/how-to...

S
shellnet, 2021-04-02
@warlinx

// Finding the index of an array element
public class Find {
public static void main(String[] args) {
int[] array = {1,9,3,4,5};
for (int i = 0; i < array.length; i++) {
if (array[i] == 5) {
int index = i;
System.out.println(index);
}
}
}
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question