Knowee
Questions
Features
Study Tools

class Output { public static void main(String args[]) { int a1[] = new int[10]; int a2[] = {1, 2, 3, 4, 5}; System.out.println(a1.length + " " + a2.length); } } Select one:a.0 10b.5 10c.0 5d.10 5

Question

class Output { public static void main(String args[]) { int a1[] = new int[10]; int a2[] = {1, 2, 3, 4, 5}; System.out.println(a1.length + " " + a2.length); } } Select one:a.0 10b.5 10c.0 5d.10 5

🧐 Not the exact question you are looking for?Go ask a question

Solution

The correct answer is d.10 5.

Here's the step by step explanation:

  1. In Java, the length property of an array returns the size of the array.

  2. int a1[] = new int[10]; Here, an integer array a1 is declared with a size of 10. So, a1.length will return 10.

  3. int a2[] = {1, 2, 3, 4, 5}; Here, an integer array a2 is declared and initialized with 5 elements. So, a2.length will return 5.

  4. System.out.println(a1.length + " " + a2.length); This line will print the length of a1 and a2 separated by a space. So, it will print "10 5".

This problem has been solved

Similar Questions

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(a1.length + " " + a2.length);       } }Select one:a.0 5b.10 5c.5 10d.0 10

Determine the output:public class Test{        public static void main(String[] args)                {                int[] x = {1, 2, 3, 4};                int[] y = x;                x = new int[2];                                for(int i = 0; i < x.length; i++)                        System.out.print(y[i] + " ");        }}Select one:a.1 2b.0 0c.0 0 0 0d.1 2 3 4

Find the output of the following code.class Output   {        public static void main(String args[])        {            int arr[] = {11, 21, 31, 41, 51};            for ( int i = 1; i < arr.length - 2; ++i)                System.out.println(arr[i] + " ");        }   }*11 21 31 4111 21 3121 3131 41 51

Select the correct answerWhat will be the output of the following Java code?class rectangle { int width; int length; int area; void area(int width, int length) { this.width = width; this.length = length; }  } class Output { public static void main(String args[]) { area obj = new area(); obj.area(5 , 6); System.out.println(obj.length + " " + obj.width); } }Options6 55 630 00 30

public class Main { public static void change(int input[]){ input = new int[5]; input[0] = 15; } public static void main(String args[]){ int arr[] = new int[5]; change(arr); System.out.println(arr[0]); }}

1/3

Upgrade your grade with Knowee

Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.