"Java" one-dimensional arrays

Source: Internet
Author: User

/*1. Three ways to initialize a one-dimensional array 2. Demonstrates the length property of an array, and gets the array lengths with length*/ Public classLinear_array { Public Static voidMain (String args[]) {intArr1[] =New int[6]; arr1[0]=1; DoubleArr2[] =New Double[]{9.0,5.5,3.6,6.9,13.4}; intArr3[] = {0,2,3,4,2,00,8}; System.out.println (arr1 [0]);//output:1System.out.println (arr2 [1]);//output:5.5System.out.println (ARR3 [2]);//Output:3//System.out.println (ARR3 [9]);        /*output:exception in thread "main" Java.lang.arrayindexoutofboundsexception:9 at linear_array.ma In (linear_array.java:16) throws array subscript overflow exception because subscript is out of bounds*/        //The subscript of an array starts with 0, and the array's maximum subscript is a number-1        intArr4[] =New int[9]; System.out.println ("The length of the array arr4 is:" + arr4.length);//Output:9        intArr5[] =New int[4+3]; System.out.println ("The length of the array arr5 is:" + arr5.length);//Output:7        /*the length of an array can only be represented by an integer of ≧0, which is usually an integer of >0, equal to 0 o'clock the length of the meaningless array may be expressed as a constant with an expression that indicates the value of length.*/    }} 

: https://gitee.com/sxyin/codes/7n3lji02udgkyvxt8r5ao79

"Java" one-dimensional arrays

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.