Question

I am writing a code for an assignment, and I want to know what this means.

The int's in the array should be initialized so that all int's at indexes of the form 0 mod 4 are - 1

What is this saying? How do I initialize a certain value at an index?

Was it helpful?

Solution

Am I getting you right, that you need to initialize elements with -1 where index modulus by equals 0

int[] arr = {1,2,3,4,5,6,7,8};
for (int i=0;i<arr.length;i+=4) arr[i]=-1

OTHER TIPS

try this

int[] a = new int[8];
Arrays.fill(a, -1);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top