Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa Java-Beginners Need help in constructing a 2 dimensionla array?
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


philippines
Need help in constructing a 2 dimensionla array?
1 Answer(s)      2 years and 9 months ago
Posted in : Java Beginners


Construct a 2 dimensional array that for each entry in the array, display the index of the first dimension data entered, the second dimension's value of the data entered, and the first dimension's value on a single line separated by : (colon).

here is what i got but i dont know what im missing thanks in advance.

public class twoDimension{ public static void main(String[] args) { int[][] a2 = new int[][]; for (int i=0; i


Advertisement
View Answers

July 11, 2012 at 11:40 AM


Here is an example of generating two-dimensional array.

import java.util.*;

public class twoDimension{
    public static void main(String[] args) { 
        Scanner input=new Scanner(System.in);
        System.out.print("Enter value of i: ");
        int a=input.nextInt();

        System.out.print("Enter value of j: ");
        int b=input.nextInt();

        int[][] a2 = new int[a][b];
        System.out.println("Enter elements of your choice: ");
        for(int i=0 ; i < a2.length ; i++){
          for(int j=0 ; j < a2[i].length ; j++){
          a2[i][j] = input.nextInt();
        }
        }
        for(int i=0 ; i < a2.length ; i++){
            System.out.println();
            for(int j=0 ; j < a2[i].length ; j++){
                System.out.print(a2[i][j]+" ");
            }
        }
    }
}


Related Tutorials/Questions & Answers:
Advertisements
Advertisements
 

 

 

DMCA.com