Q:

Java program to find the length of an array

belongs to collection: Java Array Programs

0

Java program to find the length of an array

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

In this program, we will create an array of 10 integers then we will find the length of the array using the length property.

Program/Source Code:

The source code to find the length of an array is given below. The given program is compiled and executed successfully.

// Java program to find the length of 
// an array

public class Main {
  public static void main(String[] args) {
    int[] intArr = new int[10];

    int len = intArr.length;

    System.out.println("Length of array is: " + len);
  }
}

Output:

Length of array is: 10

Explanation:

In the above program, we created a public class Main. It contains a static method main().

The main() method is an entry point for the program. Here, we created an array intArr with 10 elements and get the length of the array using the length property. After that, we printed the result.

 

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Java Array Programs

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
Java program to find prime and non-prime numbers i... >>
<< Java program to access elements of character array...