user3339453
user3339453

Reputation: 57

Initializing int in an array

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?

Upvotes: 0

Views: 53

Answers (2)

Evgeniy Dorofeev
Evgeniy Dorofeev

Reputation: 136152

try this

int[] a = new int[8];
Arrays.fill(a, -1);

Upvotes: 0

vladfau
vladfau

Reputation: 1003

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

Upvotes: 1

Related Questions