What is the output of this program?
class Output {
public static void main(String args[])
{
int a1[] = new int[10];
int a2[] = {1, 2, 3, 4, 5};
System.out.println(al.length + " " + a2. length);
D
}
Pick ONE option
105
0510
010
Answers
Answered by
2
Before I answer your question I would like to imply that you put into habit of putting a public before your class body e.g
public class Output{
Anyways the output would be
>> 10, 5
Answered by
0
Answer:
The correct answer is 10 5
Explanation:
class Output {
public static void main(String args[])
{
int a1[] = new int[10];
int a2[] = {1, 2, 3, 4, 5};
System.out.println(al.length + " " + a2. length);
}
- The length of the array defines the capacity of the array to store the elements. Here in this code, a1 array has a size of 10 which means it can store 10 integer elements.
- The next a2 array has a total of 5 elements so it has a size of 5.
- In the print statement, we are just printing the above size. So for a1.length, it is 10 and for a2.length, it is 5.
Output is 10 5
#SPJ3
Similar questions