The use of enhanced for loops in one-dimensional and two-dimensional arrays in Java _java

Source: Internet
Author: User

One-dimensional arrays:

Int[] a={1,2,3};
 for (int i:a)
{
 System.out.print (i+ "");
}

Output: 1 2 3

Two-dimensional arrays:

Import Java.util.Scanner;

public class Tet {public
	static void Main (string[] args) {
		//int[][] b={{1,2,3},{4,5,6}}; line
		int[][] A=new int[5][];//must specify the number of rows for
		(int i=0;i<5;i++)
		{
			a[i]=new int[3];//explicit Columns
		} for
		(int[) i:a)
		{for
			(int j:i)
			{
				System.out.print (j+ "");

}}}}

Output:

0 0 0
0 0 0
0 0 0
0 0 0
0 0 0

The above is the small series for you to bring to the Java enhanced for loop in one-dimensional array and two-dimensional array of the full content of the method, I hope to help you, a lot of support cloud Habitat Community ~

Related Article

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.