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
Define a class to search for a value input by the user from the list of values given below. If it is found display the message "Search successful", otherwise display the message "Search element not found" using Binary search technique.
5.6, 11.5, 20.8, 35.4, 43.1, 52.4, 66.6, 78.9, 80.0, 95.5.
The statement used to find the total number of Strings present in the string array String s[] is:
- s.length
- s.length()
- length(s)
- len(s)
A single dimensional array has 50 elements, which of the following is the correct statement to initialize the last element to 100.
- x[51]=100
- x[48]=100
- x[49]=100
- x[50]=100
What is the output of the Java code given below?
String color[] = {"Blue", "Red", "Violet"}; System.out.println(color[2].length());
- 6
- 5
- 3
- 2