Computer Science, asked by zainabparvez6008, 8 months ago

write a java statement to initialize an array with your name and roll no. ​

Answers

Answered by eklavyajain3456
0

Here's a simple program, that creates the array, puts some values in it, and displays the values.

public class ArrayDemo {

   public static void main(String[] args) {

       int[] anArray;         // declare an array of integers

       anArray = new int[10]; // create an array of integers

       // assign a value to each array element and print  

       for (int i = 0; i < anArray.length; i++) {

           anArray[i] = i;

           System.out.print(anArray[i] + " ");

       }

       System.out.println();

   }

}

The output from this program is:

0 1 2 3 4 5 6 7 8 9

This section covers these topics:

Declaring a Variable to Refer to an Array

Creating an Array

Array Initializers

Accessing an Array Element

Getting the Size of an Array

Similar questions