-
-
Save mariiaKolokolova/a902694be0c8356ae30ab0d31d3a68c2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package maricka.kolokolova; | |
import java.util.Scanner; | |
public class Main { | |
public static void main(String[] args) { | |
// TODO Auto-generated method stub | |
Scanner sc = new Scanner(System.in); | |
System.out.println("Input length of array:"); | |
int n = sc.nextInt(); | |
int[] array = new int[n]; | |
for (int i = 0; i < n; i++) { | |
System.out.println("Input [" + i + "] element:"); | |
array[i] = sc.nextInt(); | |
} | |
System.out.println("What do you want to find?"); | |
int find = sc.nextInt(); | |
System.out.println("Index for " + find + " is " + findIndex(array, find)); | |
sc.close(); | |
} | |
static int findIndex(int[] array, int find) { | |
int ind = -1; | |
for (int i = 0; i < array.length; i++) { | |
if (array[i] == find) { | |
ind = i; | |
break; | |
} | |
} | |
return ind; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment