Инициализируйте только некоторые элементы массива в JavaJAVA

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

Сообщение Anonymous »

Итак, я хочу пропустить первые и последние элементы массива для инициализации. Что я делаю не так? < /P>

public static void main(String args[]) throws Exception {

//Write code here
Scanner sc = new Scanner(System.in);
System.out.println("Input Rows: ");
int m = sc.nextInt();
System.out.println("Input Columns: ");
int n = sc.nextInt();
System.out.println("Enter values: ");
int[][] arr = new int[m][n];

for (int i = 0; i < m; i++) {
for (int j = 0; j < n; j++) {
if (arr[j] == arr[0][0] || arr[j] == arr[m][n]) {
continue;
} else {
arr[j] = sc.nextInt();
}
}

System.out.println();
}
for (int i = 0; i < m; i++) {
for (int j = 0; j < n; j++) {
System.out.print(arr[j] + " ");
}
System.out.println();
}

}
< /code>

Вот мой выход: < /p>

Input Rows:
3

Input Columns:
3

Entered Values:

0 0 0

0 0 0

0 0 0


Подробнее здесь: https://stackoverflow.com/questions/496 ... ay-in-java

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