Поиск позиции элемента в массиве с помощью Java ⇐ JAVA

Программисты JAVA общаются здесь
Anonymous
Поиск позиции элемента в массиве с помощью Java

Сообщение Anonymous »

Как найти позицию элемента в массиве в Java?
Мне не нужно печатать элемент; Мне нужно напечатать середину позиции элемента массива.
public static void main(String[] args) {
int[] array = {1, 2, 3, 4, 5};
//I need to find the middle array and in this example of the code middle array is 3 and it is in index 2.
}
}

Как в этом коде напечатать средний индекс?
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int aSize = 0;
if(scan.hasNext()){
aSize = scan.nextInt();
}

int[] a = new int[aSize];
for(int i = 0; i < aSize; i++ ){
if(scan.hasNext()){
a = scan.nextInt();
}
}


Подробнее здесь: https://stackoverflow.com/questions/791 ... -with-java

Вернуться в «JAVA»