Need help in constructing a 2 dimensionla array?

Need help in constructing a 2 dimensionla array?

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

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]+" ");
            }
        }
    }
}

Ads









Related Tutorials/Questions & Answers:
Need help in constructing a 2 dimensionla array?
Need help in constructing bubble sort
Advertisements
guys,, need help,, in java programing,, arrays
Need help to create Struts 2 MySQL based HRMS application.
Need help with this!
Printing 2 arrays
Need help
Need help
Need help
how to compare 2 arrays using java?
need help with program
Need help with nested queries
need help to create applet
need help please
Need Help in Java programming
need help with program
Need help on JAVA JSP
Friends need a help on ruby..
Need some help urgently
help me 2
hello there i need help
Need help with console program?
Need Help With This Scenario
Need Help With This Scenario
Need Help on the script
i need a help in this please
Need help with my project
need help...................please
I have need to help
Need urgent help with C++ errors!
need someone to do/help with code

Ads