Page 327 - ComputerScience_Class_11
P. 327
The above statement creates a character type array of size 5 and stores alphanumeric elements in it at compile time.
The character array elements are enclosed within single quotes.
String array[ ]={"Joy","Gopal"};
The above statement creates a string type array of size 2 and stores two strings at compile time. The string array
elements are enclosed within double quotes.
The below program helps understand the different types used in an array and explains the logic.
Program 3 Write a Java program to print the names and roll numbers of the following students.
Name: Aarav, Aditya, Rohan, Rahul, Arjun and Roll numbers: 1, 2, 3, 4, 5.
1 import java.util.*;
2 class name_roll
3 {
4 public static void main(String args[]) {
5 String name[ ]={"Aarav", "Aditya", "Rohan", "Rahul", "Arjun"};
6 int roll[ ]={1,2,3,4,5};
7 int i;
8 for(i=0; i<5; i++) {
9 System.out.println(name[i] + " " + roll[i]);
10 }
11 }
12 }
The output of the preceding program is as follows:
BlueJ: Terminal Window - Java
Options
Aarav 1
Aditya 2
Rohan 3
Rahul 4
Arjun 5
11.3.2 Dynamic Declaration
In this type of array declaration, the size of the array may or may not be fixed and the memory is allocated at run
time. In this declaration, we need not specify the values or the elements of the array in the program itself. It takes the
values from the user at run time or the values are received from some execution. The table given below demonstrates
different data types used in the dynamic declaration of an array.
Arrays 325

