Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,907 questions

51,839 answers

573 users

How to implement indexOf function on int array in Java

1 Answer

0 votes
public class Program {
    public static void main(String[] args) {
        int[] arr = {6, 7, 8, 4, 2, 1, 1, 7, 5, 8, 9, 5, 3};

        System.out.println(indexOf(arr, 8));
    }

    public static int indexOf(int[] arr, int value) {
        for (int i = 0; i < arr.length; i++) {
            if (arr[i] == value) {
                return i;
            }
        }
        return -1;
    }
}


 
/*
run
 
2
 
*/

 



answered Jun 1, 2024 by avibootz

Related questions

1 answer 98 views
1 answer 203 views
1 answer 162 views
1 answer 154 views
1 answer 86 views
86 views asked Oct 4, 2023 by avibootz
1 answer 186 views
...