Java array matrix problem.. please help!
I am working on an assignment that compares two numbers from adjacent columns and swaps them if the one on the right is smaller than the one on the left. Basically, it's two columns being compared(i and j) and i is the smallest. At first, i is the first column and j is the second column. Then, i is the second column and j is the third column. Then i is the third column and j is the fourth column. So far, I have typed up this code(I think it's too long!):
Code:
public class MatrixProgram
{
public static void main(String args)
{
int[][] matrix = new matrix [4][4];
matrix[1][1] = 1;
matrix[1][2] = 2;
matrix[1][3] = 1;
matrix[1][4] = 4;
matrix[2][1] = -4;
matrix[2][2] = 1;
matrix[2][3] = -2;
matrix[2][4] = 2;
matrix[3][1] = 0;
matrix[3][2] = -3;
matrix[3][3] = 1;
matrix[3][4] = -9;
matrix[4][1] = 7;
matrix[4][2] = 5;
matrix[4][3] = 0;
matrix[4][4] = 2;
swapMatrix();
swapMatrix1();
swapMatrix2();
swapMatrix3();
swapMatrix4();
swapMatrix5();
swapMatrix6();
swapMatrix7();
swapMatrix8();
swapMatrix9();
swapMatrix10();
swapMatrix11();
}
public void swapMatrix()
{
if(matrix[1][1] > matrix[1][2])
{
int[][] temp = matrix[1][1];
matrix[1][1] = matrix[1][2];
matrix[1][2] = temp;
System.out.println(temp);
}
else
{
System.out.println(matrix[1][1]);
}
}
public void swapMatrix1()
{
if(matrix[2][1] > matrix[2][2])
{
int[][] temp = matrix[2][1];
matrix[2][1] = matrix[2][2];
matrix[2][2] = temp;
System.out.println(temp);
}
else
{
System.out.println(matrix[2][1]);
}
}
public void swapMatrix2()
{
if(matrix[3][1] > matrix[3][2])
{
int[][] temp = matrix[3][1];
matrix[3][1] = matrix[3][2];
matrix[3][2] = temp;
System.out.println(temp);
}
else
{
System.out.printnln(matrix[3][1]);
}
}
public void swapMatrix3()
{
if(matrix[4][1] > matrix[4][2])
{
int[][] temp = matrix[4][1];
matrix[4][1] = matrix[4][2];
matrix[4][2] = temp;
System.out.println(temp);
}
else
{
System.out.println(matrix[4][1]);
}
}
public void swapMatrix4()
{
if(matrix[1][2] > matrix[1][3])
{
int[][] temp = matrix[1][2];
matrix[1][2] = matrix[1][3];
matrix[1][3] = temp;
System.out.println(temp);
}
else
{
System.out.println(matrix[1][2]);
}
}
public void swapMatrix5()
{
if(matrix[2][2] > matrix[2][3])
{
int[][] temp = matrix[2][2];
matrix[2][2] = matrix[2][3];
matrix[2][3] = temp;
System.out.println(temp);
}
else
{
System.out.println(matrix[2][2]);
}
}
public void swapMatrix6()
{
if(matrix[3][2] > matrix[3][3])
{
int[][] temp = matrix[3][2];
matrix[3][2] = matrix[3][3];
matrix[3][3] = temp;
System.out.println(temp);
}
else
{
System.out.println(matrix[3][2]);
}
}
public void swapMatrix7()
{
if(matrix[4][2] > matrix[4][3])
{
int[][] temp = matrix[4][2];
matrix[4][2] = matrix[4][3];
matrix[4][3] = temp;
System.out.println(temp);
}
else
{
System.out.println(matrix[4][2]);
}
}
public void swapMatrix8()
{
if(matrix[1][3] > matrix[1][4])
{
int[][] temp = matrix[1][3];
matrix[1][3] = matrix[1][4];
matrix[1][4] = temp;
System.out.println(temp);
}
else
{
System.out.println(matrix[1][3]);
}
}
public void swapMatrix9()
{
if(matrix[2][3] > matrix[2][4])
{
int[][] temp = matrix[2][3];
matrix[2][3] = matrix[2][4];
matrix[2][4] = temp;
System.out.println(temp);
}
else
{
System.out.println(matrix[2][3]);
}
}
public void swapMatrix10()
{
if(matrix[3][3] > matrix[3][4])
{
int[][] temp = matrix[3][3];
matrix[3][3] = matrix[3][4];
matrix[3][4] = temp;
System.out.println(temp);
}
else
{
System.out.println(matrix[3][3]);
}
}
public void swapMatrix11()
{
if(matrix[4][3] > matrix[4][4])
{
int[][] temp = matrix[4][3];
matrix[4][3] = matrix[4][4];
matrix[4][4] = temp;
System.out.println(temp);
}
else
{
System.out.println(matrix[4][3]);
}
}
}
When I compile it, I get 97! errors saying that it can't find the variable "matrix"
Is there a way to fix the problem and is there any other, shorter way to accomplish this task without all these lines of code? Thanks in advance!