#### 2–D Array in Java Program

2-D array is collection of row and column. We can also write row x column. We can also call collection of 1-D array.

In advance level, our data will be retrieving from database in one object format, that time we need 2-D array to split data in normal form.

**In this blog, we see how to store data in 2-D array and how to find maximum number from each row.**

**Example**

C0 | C1 | C2 | Ans | ||

R0 | 56 | 34 | 23 | 56 | |

R1 | 67 | 34 | 73 | 73 | |

R2 | 45 | 87 | 34 | 87 |

*C0, C1 and C2 are columns; R0, R1 and R2 are rows.*

**Let’s see how to work in program.**

import java.util.*;

class arr6

{

public static void main(String args[])

{

Scanner in1 = new Scanner(System.in);

double[][] x = new double[3][3];

int i,j;

System.out.println(“Enter Array : “);

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

{

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

{

x[i][j] = in1.nextDouble();

}

}

System.out.println(“ Maximum Number From Each Row:“);

double max = 0;

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

{

max = x[i][0]; // set 1^{st}number of each row

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

{

if(x[i][j] > max) // compare every row value with max

{

max = x[i][j]; // assign maxvalue into max var.

}

System.out.print(x[i][j] + “ ”); // display each value

}

System.out.println(“ | ” + max); // display max value

}

}

}

**Output:**

Enter Array:

23 -12 14

12 78 22

45 21 43

Maximum Number from Each Row

23 -12 14 | 23

12 78 22 | 78

45 21 43 | 43

**Basic to Advance Level Tutorial.**

No | Title |

1 | Find min and maximum number from 2-D Array |

2 | Find maximum from each column [Hint : use 1-D array for this example] |

3 | Find sum and average of each row |

4 | Count number of positive and negative numbers from each column. |

### Share and Enjoy

194total visits,1visits today