# Two- Dimensional Array

Abhishek Sisodia
Two- Dimensional Array
Posted in : Java Beginners
I am new in java programming. I am creating a two-dimensional array. This is my code
**
class BinaryNumbers
{
public static void main(String[] args)
{
//create a two-dimensional array
int ROWS = 21;
int COLS = 2;

int[][] a2 = new int[ROWS][COLS];

//... Print array in rectangular form
for (int i =0; i < ROWS; i++) {
for (int j = 0; j < COLS; j++) {
System.out.print(" " + a2[i][j]);
}
System.out.println("");
}
}
}
I want to enter this data into this array
Decimal Binary
1 1
2 10
3 11
4 100
5 101
6 110
7 111
8 1000
9 1001
10 1010
11 1011
12 1100
13 1101
14 1110
15 1111
16 10000
17 10001
18 10010
19 10011
20 10100

February 22, 2010 at 12:48 PM

Hi Friend,

Try the following code:

class BinaryNumbers
{
static int ROWS = 20;
static int COLS = 2;
public static void main(String[] args){
int a2[][]={{1,1},{2,10},{3,11},{4,100},{5,101},{6,110},{7,111},{8,1000},{9,1001},{10,1010},{11,1011},
{12,1100},{13,1101},{14,1110},{15,1111},{16,10000},{17,10001},{18,10010},{19,10011},{20,10100}};
System.out.println("Decimal Binary");
for (int i =0; i < ROWS; i++) {
for (int j = 0; j < COLS; j++) {
System.out.print(" " + a2[i][j]);
}
System.out.println("");
}
}
}

Thanks

February 23, 2010 at 12:00 AM

Hey,
Here is the code which builds Binary Numbers dynamically where you need not give binary numbers explicitly. Just the decimal no. is sufficient.

public class BinaryNumbers {

public static void main(String[] args) {
int ROWS = 26;
int COLS = 2;
int[][] binaryArray = new int[ROWS][COLS];
for (int i = 1; i < ROWS; i++) {
String binaryNo = Integer.toBinaryString(i);
for (int j = 0; j < COLS - 1; j++) {
binaryArray[i][j] = i;
binaryArray[i][++j] = Integer.parseInt(binaryNo);
}
}
for (int i = 1; i < ROWS; i++) {
for (int j = 0; j < COLS; j++) {
System.out.print(binaryArray[i][j] + " ");
}
System.out.println("");
}
}

}

February 23, 2010 at 12:17 AM

Hi,
Here is another code same as above that prints binary numbers on the fly with little modification.
Just give how many no.of binary numbers you wanna print starting from 1 in the console.May seem complex, but easy..

import java.util.Scanner;

public class BinaryNumbers {

public static void main(String[] args) {
System.out
.println("Enter the no. of binary numbers you want to print : ");
Scanner scan = new Scanner(System.in);
int ROWS = scan.nextInt() + 1;
int[][] binary = new int[ROWS][];
for (int i = 1; i < ROWS; i++) {
String binaryNo = Integer.toBinaryString(i);
binary[i] = new int[2];
binary[i][0] = i;
binary[i][1] = Integer.parseInt(binaryNo);
}
/* Print Array */
for (int i = 1; i < ROWS; i++) {
System.out.println(binary[i][0] + " " + binary[i][1]);
}
}
}

Snippet of o/p:

Enter the no. of binary numbers you want to print :
40
1 1
2 10
3 11
4 100
.
.
.
38 100110
39 100111
40 101000

Regards,
javaquest2010

February 26, 2010 at 7:32 AM

Thank you very much every one

php two dimensional array
php two dimensional array  php two dimensional array example
two dimensional array
two dimensional array  how tow dimensional array works.How those loopes get incremented .and how every time the value of k changes
Two Dimensional array program
Two Dimensional array program  consider a two dimensional array... to elements of the array such that the last element become the first one and the first become the last.let the program output elements of the first array
Two Dimensional Array Program
Two Dimensional Array Program Using Nested for loop...; program . In this session we will teach how to use of a two dimensional array... are going to make two dimensional array having three row and three columns.
Two- Dimensional Array - Java Beginners
Two- Dimensional Array  I am new in java programming. I am creating a two-dimensional array. This is my code ** class BinaryNumbers { public static void main(String[] args) { //create a two-dimensional array int ROWS = 21
how do i begin a two dimensional array?
how do i begin a two dimensional array?  I'm new to java programming and need to create a two dimensional array that enters exactly what is entered in the first dimension and then the first non-white space character of what
Two dimensional array in java
Two dimensional array in java. In this section you will learn about two-dimensional array in java with an example. As we know that array is a collection.... int arr[][]; Here arr is a two-dimensional array of type int. To create an array
Two Dimensional Array Program
Two Dimensional Array Program    ... will learn how to display arrange form of two dimensional array program... a integer for array declaration Two dimensional array program. We are going
Square Elements of Two Dimensional Array
the two dimensional array program and its square. This session provide you... Square Elements of Two Dimensional Array   ...: We are going to display the square of two matrix. Firstly, we have to define
Two Dimensional Array Program Using Nested For Loop
Two Dimensional Array Program Using Nested For Loop ... dimensional array program. Firstly, we have to define class "TwoDimensional ". We are going to make a integer for array declaration Two dimensional array
reverse two dimensional arrays in java
reverse two dimensional arrays in java  reverse array elements in two dimensional array such that the last element becomes the first
A single dimensional array is called
A single dimensional array is called  What is a single dimensional array called?   A single dimensional array is called LIST
Dividing Element of Two Dimensional Array
Dividing  Element of Two Dimensional Array...;ArrayDivideMatrix". Here you will learn how to use two matrix array for developing Java program.  The java two dimensional array program is operate the two
need help with two dimensional array that takes input from user and bubble sorts and selections sorts
need help with two dimensional array that takes input from user and bubble... cannot figure out how i can declare a two dimensional array without knowing how... many words he/she types without using an array list.   Thank you. I
two dimensional - Java Beginners
two dimensional  write a program to create a 3*3 array and print the sum of all the numbers stored in it.  Hi Friend, Try the following code: import java.io.*; import java.util.*; public class matrix
one dimensional array program
one dimensional array program  Design and implement a java program that will read a file containing numbers and compute the following statistics: the rannge( low, high), the average and the median(middle number). Notes
Declare string array in Java (one and two dimensional)
Declare string array in Java (one and two dimensional... dimensional array and two dimensional as well. 1. String arr[] = new String...] + " "); } //declare and initialize two dimensional array String dim2
Two-dimensional arrays
; Two-dimensional arrays are defined as "an array of arrays"... of arrays of  ints". Such an array is said to be a two-dimensional array. ... in each of those arrays. To process a two-dimensional array, we use nested
one dimensional array using java
one dimensional array using java  design and implement a java program that will read a file containing numbers and compute the following statistics: the range(low,high) the average and the median
Need coding help - two dimensional matrix and it returns back a boolean.
Need coding help - two dimensional matrix and it returns back a boolean.  I need to write a code method that accepts a two dimensional integer arrays as the argument and returns true if the array or matrix is left or right
Three Dimensional Array program
Three Dimensional Array program   ... will learn how to use three dimensional array. Firstly, we have to define class... are going to make three dimensional array having multi rows and columns. By using
Display tow dimensional array using one for loop in java
Display tow dimensional array using one for loop in java  Display tow dimensional array using one for loop in java
Array in Java
. Different types of array used in Java are One-dimensional, Two-dimensional and multi...[] = {50,60,70,80,90}; Two-dimensional arrays: Two-dimensional arrays...An Array is the static memory allocation that holds a fixed number of values
Display tow dimensional array by matrix form using one for loop in java
Display tow dimensional array by matrix form using one for loop in java  Display tow dimensional array by matrix form using one for loop in java
Multi-dimensional arrays
that supports it, the element of the two-dimensional array x is denoted by x[i,j]. .... It does, however, supports an array of arrays. In Java, a two-dimensional array...; So far we have studied about the one-dimensional and two
C Array of String
and handled like a 2d(two dimensional) arrays. You can see in the given example that we have declare a 2 dimensional character array consisting of three 'rows' and twelve... C Array of String
Creation Time Comparison of Multi Dimensional Array- Java Tutorials
Creation Time Comparison of Multi Dimensional Array In this section, we will compare the creation time between the different size/dimension of array.  As you know that multidimensional array is the array of arrays. Practically
plz try to clear my doubt for shuffling multi-dimensional array
plz try to clear my doubt for shuffling multi-dimensional array  hi... want to shuffle the ful entire multi-simensional array means wat v want to do... final int size = 5; private int[][] array = new int[size][size]; private
Multidimensional Array Java
to store it in an array. We use mostly two types of arrays that is simple array and multi dimensional array.   In the example given below we have used two dimensional array. A two dimensional array can be thought as a grid
two dimansional array - Java Beginners
two dimansional array  Modify the following program so that it computes and prints the tables of powers from 1 to 15.( 1 to 15 to the power 1, Squared, and Cubed: like below) it should look like 1 1 1 2 4 8 3 9 27 and so
To find first two maximum numbers in an array
To find first two maximum numbers in an array  Java program to find first two maximum numbers in an array,using single loop without sorting array
Tutorials