hat sich erledigt....
import java.util.*;
class FlipMatrix
{
public static void main(String args[])
{
test(3,4);
test(4,4);
test(4,5);
}
private static void test(int rows, int cols)
{
System.out.println("Test with "+rows+" rows and "+cols+" columns");
List<String> matrix = create(rows,cols);
System.out.println(matrix);
print(matrix, rows,cols);
flip(matrix,rows,cols);
System.out.println("Flipped:");
System.out.println(matrix);
print(matrix,rows,cols);
System.out.println("");
}
private static List<String> create(int rows, int cols)
{
List<String> matrix = new ArrayList<String>();
for (int i=1; i<=rows; i++)
{
for (int j=1; j<=cols; j++)
{
matrix.add(i+"/"+j);
}
}
return matrix;
}
private static void print(List<String> matrix, int rows, int cols)
{
for (int i=0; i<rows; i++)
{
for (int j=0; j<cols; j++)
{
int index = (rows-1-i)*cols+j;
System.out.print(matrix.get(index)+" ");
}
System.out.println("");
}
}
private static void flip(List<String> matrix, int rows, int cols)
{
for (int i=0; i<rows/2; i++)
{
for (int j=0; j<cols; j++)
{
int i0 = (rows-1-i)*cols+j;
int i1 = i*cols+j;
String temp = matrix.get(i0);
matrix.set(i0, matrix.get(i1));
matrix.set(i1, temp);
}
}
}
}