Click here to watch in Youtube :
https://www.youtube.com/watch?v=TqS4S2d0tr4&list=UUhwKlOVR041tngjerWxVccw
Click the below Image to Enlarge
Java Tutorial : Java Array (Multidimensional Array - String Create and Intialize) |
class ArrayDemo { public static void main(String[] args) { String[][] strArray = { { "Ram", "Peter" }, { "Apple", "Ball" }, { "Bike", "Car" } }; System.out.println("Element at strArray[0][0] : " + strArray[0][0]); System.out.println("Element at strArray[0][1] : " + strArray[0][1]); System.out.println(); System.out.println("Element at strArray[1][0] : " + strArray[1][0]); System.out.println("Element at strArray[1][1] : " + strArray[1][1]); System.out.println(); System.out.println("Element at strArray[2][0] : " + strArray[2][0]); System.out.println("Element at strArray[2][1] : " + strArray[2][1]); } }
Element at strArray[0][0] : Ram Element at strArray[0][1] : Peter Element at strArray[1][0] : Apple Element at strArray[1][1] : Ball Element at strArray[2][0] : Bike Element at strArray[2][1] : Car
public class ArrayLoopDemo { public static void main(String[] args) { String[][] strArray = { { "Ram", "Peter" }, { "Apple", "Ball" }, { "Bike", "Car" } }; int rows = strArray.length; System.out.println("Number of rows : " + rows+"\n"); for (int i = 0; i < rows; i++) { int columns = strArray[i].length; System.out.println("Number of columns in row "+ i +" is : " + columns); for (int j = 0; j < columns; j++) { System.out.println("Element at " + "strArray[" + i + "]" + "[" + j + "] : " + strArray[i][j]); } System.out.println(); } } }
Number of rows : 3 Number of columns in row 0 is : 2 Element at strArray[0][0] : Ram Element at strArray[0][1] : Peter Number of columns in row 1 is : 2 Element at strArray[1][0] : Apple Element at strArray[1][1] : Ball Number of columns in row 2 is : 2 Element at strArray[2][0] : Bike Element at strArray[2][1] : Car
https://sites.google.com/site/javaee4321/java/ArrayDemoMultiDimensionalStrCreateAndInitializeApp.zip?attredirects=0&d=1
See also:
No comments:
Post a Comment