Computer Science, asked by hrdpbhamra, 2 months ago

write array declaration in java for :- 1-D array of 5 integers initialised to 1​

Answers

Answered by anindyaadhikari13
3

Answer:

To declare 1D array of 5 integers initialised to 1, write the códe given below.

int a[] = {1,1,1,1,1}

To print the array, we can write -

System.out.println(Arrays.toString(a));

Output: [1, 1, 1, 1, 1]

Learn More:

Array: An array is a collection of similar objects.

Syntax to declare 1D array in Java:

data_type array_name[] = new data_type[size];

To initialise array,

data_type variable_name = {value1, value2,...};

Arrays are of two types - Static array and dynamic array.

In static array, the size of the array cannot be changed and elements of array cannot be deleted.

In dynamic array, we can easily change the size of the array and we can also delete elements.

Similar questions