V
V
Vladimir Gudkov2022-04-09 21:47:56
Arrays
Vladimir Gudkov, 2022-04-09 21:47:56

How to assign values ​​to arrays?

Hello!
The essence of the question is this: how to write code correctly so that the array index i increases by a given parameter?
and why does it return 16 in each element? If x is replaced by i then everything works...

package com.java;

public class Main {

public static void main(String[] args) {
int [] num = new int[15];
for (int i = 0; i < num.length; i++) {
for (int x = 0; x < 15; x++) {
num[i] = x+2;
}

System.out.println(num[i]);
}
}

}

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question