0% found this document useful (0 votes)
2 views

Multi Dimes Ional Array

The document provides examples of Java programs demonstrating the use of multi-dimensional arrays, including two-dimensional and three-dimensional arrays. It covers array initialization, assignment of values, and printing the arrays. The examples illustrate how to access specific elements within these arrays.

Uploaded by

gautamideore13
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Multi Dimes Ional Array

The document provides examples of Java programs demonstrating the use of multi-dimensional arrays, including two-dimensional and three-dimensional arrays. It covers array initialization, assignment of values, and printing the arrays. The examples illustrate how to access specific elements within these arrays.

Uploaded by

gautamideore13
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Java Multi-Dimensional Arrays

// Java Program to Demonstrate

// Multi Dimensional Array

import java.io.*;

public class Main {

public static void main(String[] args){

int[][] arr = new int[10][20];

arr[0][0] = 1;

System.out.println("arr[0][0] = " + arr[0][0]);

// Java Program to demonstrate the use of

// Two Dimensional Array

import java.io.*;

class Main {

public static void main(String[] args){


// Array Intialised and Assigned

int[][] arr = { { 1, 2 }, { 3, 4 } };

// Printing the Array

for (int i = 0; i < 2; i++){

for (int j = 0; j < 2; j++)

System.out.print(arr[i][j]+" ");

System.out.println();

// Java Program to demonstrate the use of

// Two Dimensional Array

public class TwoDArray {

public static void main(String[] args) {

// Row and Columns in Array

int n = 2;

int m = 2;

// Array declared and initialized

int[][] arr = new int[n][m];

int it = 1;

// Assigning the values to array

for (int i = 0; i < n; i++) {

for (int j = 0; j < m; j++) {


arr[i][j] = it;

it++;

// Printing the Array

for (int i = 0; i < n; i++) {

for (int j = 0; j < m; j++)

System.out.print(arr[i][j] + " ");

System.out.println();

Example

// Java Program to Demonstrate

// Three Dimensional Array

import java.io.*;

class Main {

public static void main(String[] args){

// Array Created and Initialized

int[][][] arr = { { { 1, 2 }, { 3, 4 } }, { { 5, 6 }, { 7, 8 } } };

// Defining the x,y,z in Multi

// Dimensional Array

int n = arr.length;

int m = arr[0].length;
int o = arr[0][0].length;

// Printing the Array

for (int i = 0; i < n; i++) {

for (int j = 0; j < m; j++){

for(int k=0; k < o; k++)

System.out.print(arr[i][j][k] + " ");

System.out.println();

System.out.println();

Example of three dimensional array

// Java Program to Demonstrate Accessing

// Three Dimensional Array by Index

import java.io.*;

class GFG {

public static void main(String[] args){

// Creating an Array

int[][][] arr = { { { 1, 2 }, { 3, 4 } },

{ { 5, 6 }, { 7, 8 } } };

// Printing array at index 0 , 0 , 0

System.out.println("arr[0][0][0] = " + arr[0][0][0]);

You might also like