give me two good java programs on 2D array for ISC project with question
Answers
Answered by
0
//*************Program to demonstrate the use of 2D Array************import java.util.*;public class ArrayEx{public static void main(String[] args){ System.out.println("Enter no of rows & Columns:\n----------------------");System.out.print("No. of rows: "); int rows=new Scanner(System.in).nextInt(); System.out.print("No. of columns: "); int cols=new Scanner(System.in).nextInt();int [][] a=new int[rows][cols];int count=rows*cols;System.out.println("Insert the "+count+" numbers of the 2D array: ");for(int i=0;i<rows;i++) { for(int j=0;j<cols;j++) { a[i][j]=new Scanner(System.in).nextInt(); count--; if(count>1) System.out.println(count+ " elements are remaining"); if(count==1) System.out.println(count+ " element is remaining"); if(count==0) System.out.println("All elements inserted\n\n"); } } System.out.println("Displaying the 2D array in the matrix form:-\n----------------------\n" ); for(int i=0;i<rows;i++) { for(int j=0;j<cols;j++) { System.out.print(a[i][j]+" "); } System.out.print("\n"); }}}
Attachments:
Similar questions