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
2 Likes
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
3 Likes
Related Questions
Name the method of search depicted in the below picture:
A single dimensional array contains 37 elements. Which of the following represents the index of its second-to-last element.
A class teacher wants to arrange the names of her students in alphabetical order. Define a class NameSorter that stores the given names in a one-dimensional array. Sort the names in alphabetical order using Bubble Sort technique only and display the sorted names.
Aryan, Zoya, Ishaan, Neha, Rohan, Tanya, Manav, Simran, Kabir, Pooja
public class NameSorter { void bubbleSort(String names[]) { int len = names.length; _______(1)_________ { _______(2)_________ { _______(3)_________ { String t = names[j]; _______(4)_________ _______(5)_________ } } } } public static void main(String[] args) { String arr[] = {"Aryan", "Zoya", "Ishaan", "Neha", "Rohan", "Tanya", "Manav", "Simran", "Kabir", "Pooja" }; NameSorter obj = new NameSorter(); obj.bubbleSort(arr); for (int i = 0; i < arr.length; i++) { System.out.println(arr[i]); } } }
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]?