800+Questions XII Information Technology Code 802
Buy Chapter wise Question bank Class 12 Information Technology 802
800+Questions XII Information Technology Code 802
Topics: Arrays
Que 1. What is Array?
Answer: Arrays are variables that can hold more than one value, they can hold a list of values of the same type.
Arrays are the collection of variables of similar types.
Que 2. How can you create an Array?
Answer: Creation of array is a two stpes process.
(i) Array declaration
syntax : datatype [] arrayvariablename;
(ii) Array definition / Allocation of memory
syntax : arrayvariablename = new datatype[size]
Que 3. How can you create and initialized array statically?
Answer: To create and initialized array statically, follow these steps:
datatype[ ] arrayvariablename = {value1, value2, …., value-n}
For example :
int[] marks = {2, 5, 3, 8}
String[] name = {“Anjeev”, “Amit”, “Anuj”}
Que 4. What is the importance of [ ]?
Answer: The [] brackets after the data type tell the Java compiler that instead of a single value,
the marks variable is an array that can hold more than one value, each of type data_type.
Que 5. What is the use of new operator?
Answer: The new operator is used to allocate memory at run time. In array, the size of the array is specify by using new keyword.
marks = new double[5];
Que 6. Which property of the array returns the size of the array?
Answer: length property
Que 6. Write a program to create an array to store marks of five subjects and print their marks?
Answer:
public static void main(String[] args){
double [] marks;
marks = new double[5];
marks[0] = 23;
marks[1] = 25;
marks[2] = 30;
marks[3 = 29;
marks[4] = 28;
for(int i =0; i < 6; i++)
System.out.println(marks[i]);
}
Que 7. Write a program to create an array to store age of ten students and print their marks?
Answer:
public static void main(String [] args) {
int[] age = {25,12,14,18,19,30,36,38, 28, 20};
System.out.println(“Size of array :” +(age.length));
int total = 0;
for(int i =0; i < age.length; i++)
total += age[i];
System.out.println(“Average Age :”+(total/age.length));
}
Que 8. Write the name of exception occurs when you access invalid index?
Answer: An Array index out of bounds Exception