Computer Applications
Which of the following is a valid way to declare and initialize an integer array to store the ages of 50 students?
Java Arrays
1 Like
Answer
int age[] = new int[50];
Reason — In Java, arrays are declared and initialized using the following syntax:
dataType arrayName[] = new dataType[size];
Here, int age[] = new int[50];
correctly declares an array of size 50
to store integer values.
Answered By
2 Likes
Related Questions
Define a class to accept values into 4x4 array and find and display the sum of each row.
Example:
A[][]={{1,2,3,4},{5,6,7,8},{1,3,5,7},{2,5,3,1}}
Output:
sum of row 1 = 10 (1+2+3+4) sum of row 2 = 26 (5+6+7+8) sum of row 3 = 16 (1+3+5+7) sum of row 4 = 11 (2+5+3+1)
Consider the following program segment and answer the questions given below:
int x[][] = {{2,4,5,6}, {5,7,8,1}, {34, 1, 10, 9}};
(a) What is the position of 34?
(b) What is the result of x[2][3] + x[1][2]?
Name the method of search depicted in the below picture:
Name the below structure:
- One dimensional array
- Two Dimensional array with 4 rows and 5 columns
- Three dimensional array
- Two Dimensional array with 5 rows and 4 columns