Java get Array (two-dimensional array) Length instance program

Source: Internet
Author: User

We probably know that JS has a length function, and Java has the length function.

Cases

If the array is data[], then data.length

Code to copy code as follows
byte[] Phone =new byte[81]; Create an array of type byte with a length of 81
Phone[i]!=0 in phone[i]! The position of the array i is not equal to 0

Such as:

Code to copy code as follows
byte[] Phone =new byte[81]; Create an array of type byte with a length of 81
Phone[1]!=0 in phone[1]! The second value of the array is not equal to 0

Give an example to the landlord at the same time:

Code to copy code as follows
public class Studyarrary {

/**
* @param args
*/
public static void Main (string[] args) {
TODO auto-generated Method Stub
byte[] Phone =new byte[81]; Create an array of type byte with a length of 81
for (int a = 0; a < Bayi; a++)
Phone[a]= (Byte) A; The position of the array i is not equal to 0

for (int i = 0; i < Bayi; i++) {
if (phone[i]!=0) {
System.out.println ("phone[" +i+ "] is not equal to 0" + ", Phone" +i+ "is" +phone[i ");
}
Else
System.out.println ("phone[" +i+ "] equals 0" + ", Phone" +i+ "is" +phone[i ");
}
}

}

Length of a two-dimensional array

Code to copy code as follows
Public C (www.111cn.net) Lass lesson{
public static void Main (String [] args) {

How to declare a two-dimensional array:
data type [] Array name = new data type [length] [length];
data type [] Array name = {{123},{456}};


int [] [] num = new int [3][3]; Defines a two-dimensional array of three rows and three columns
Num[0][0] = 1; Assign a value to the first element of the first row
NUM[0][1] = 2; Assign a value to the second element of the first row
NUM[0][2] = 3; Assign a value to the third element of the first row

NUM[1][0] = 4; Assign a value to the first element in the second row
NUM[1][1] = 5; Assign a value to the second element of the second row
NUM[1][2] = 6; Assign a value to the third element of the second row

Num[2][0] = 7; Assign a value to the first element in the third row
NUM[2][1] = 8; Assign a value to the second element of the third row
NUM[2][2] = 9; Assign a value to the third element of the third row
for (int x = 0; x
for (int y = 0; y
System.out.print (Num[x][y]);
}
SYSTEM.OUT.PRINTLN ("/n");
}
}
}

Array value Arr[x][y] indicates that the value specified is the y column of row x.
When using a two-dimensional array object, note the length represented by
The array name is followed by a length (such as Arr.length), which refers to a few rows (row);
Specify the index with length (such as Arr[0].length), which is the number of elements owned by the row, that is, the column
From:http://www.111cn.net/jsp/java/46864.htm

Java get Array (two-dimensional array) Length instance program

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.