Welcome to the Java Programming Forums

The professional, friendly Java community. 21,500 members and growing!

The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.

>> REGISTER NOW TO START POSTING

1. ## Please help me how to convert 2-d array to 1-d array in java :( here's the code

```import java.io.*;
public class Program2 {
public static void print_array(int[][] numbers)
{

for (int i=1; i<numbers.length; i++) {
System.out.print("" + i + " |");
for (int a=1; a<numbers[i].length; a++)
System.out.print("\t" + numbers[i][a]);
System.out.println(); }

}

public static void main(String[] args) throws IOException {

String yesno="u";
boolean isExit=false;

do{

String row, column;
int Columns = 0;
int Rows = 0;
System.out.print("\n");
System.out.print("ENTER A NUMBER : ");
Rows= Integer.parseInt( row );

int values[][] = new int[Rows+1][Rows+1];
int [][] m = new int[Rows][];
for (int i=0; i < Rows; i++)
m[i] = new int[Rows];
for (int i=0; i < values.length; i++)
for (int a=0; a < values[i].length; a++)
values[i][a] = i*a;
System.out.print("\n");
for (int i=0; i < values.length; i++){
System.out.print(" " + i + " ");
}
System.out.println();
for (int i=0; i < values.length; i++){
System.out.print("" + "" + "---");
}
System.out.println();
print_array(values);
System.out.print("\n\n");

System.out.println("Try again (press 1 if yes/press 2 if no)?");

if(yesno.equalsIgnoreCase("1")) {
isExit=false;
} else if(yesno.equalsIgnoreCase("2")) {
isExit=true;
}

}while(!isExit);
System.out.print("Goodbye!");

}
}```

2. ## Re: Please help me how to convert 2-d array to 1-d array in java :( here's the code

More information needed. What's the problem? What have you tried? Why are you doing this?

4. ## Re: Please help me how to convert 2-d array to 1-d array in java :( here's the code

this is a multiplication table 2d array, can you convert it to 1d array? this is my problem.. i don't how to convert it to 1d array

5. ## Re: Please help me how to convert 2-d array to 1-d array in java :( here's the code

Do you mean just take all the values and stick them in one array?

Get the total size of the 2D array by doing length*width
```int[][] tda = new int[5][5];
int total = tda.length*tda[0].length;
int[] oda = new int[total];```

```int index = 0;