ADVERTISEMENT
ADVERTISEMENT

Java program to find the length of an array

Given an integer array, we have to find the length of an array.
Submitted by Nidhi, on March 13, 2022

Problem Solution:

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.

Java Array Programs »


ADVERTISEMENT
ADVERTISEMENT


Comments and Discussions!



ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.