package test;
import java.util.*;
public class test {
public int[][] left (int matrix[][]) {
for(int i=0; i<=3;i++)
for (int j=2;j>=0;j--)
{
if (matrix[i][j] ==0)
{
for (int k=j+1; k<=3;k++)
{
matrix[i][k-1]=matrix[i][k]; // chuyen
}
for (int l=3; l>=0;l--)
{
if (matrix[i][l] == 0) continue;
else matrix[i][l] =0;
if (matrix[i][l] != 0) break;
}
}
}
return matrix;
}
public static void main(String[] args)
{
Scanner in = new Scanner(System.in);
int i,j;
int[][] a = new int[3][3];
for (i=0;i<=2;i++)
for (j=0;j<=2;j++)
{
System.out.print("input a" +i + j);
a[i][j]= in.nextInt();
}
left(a);
for (i=0;i<=2;i++)
{
for (j=0;j<=2;j++)
{
System.out.print(a[i][j]);
}
System.out.println("");
}
}
}
This method insert takes as input int[][]
array, and I want a method to return a new array. In example, I got an array.
a[][]=
{
0 0 2 0
0 2 0 0
0 2 2 2
2 0 0 0
}
And I try to use method like that : left(a);
to return the new array a but it not work .
The new array i want to return like:
{
2 0 0 0
2 0 0 0
2 2 2 0
2 0 0 0
}
(incremental element to the left, except 0)
Multiple markers at this line
- Return type for the method is missing
- Syntax error, insert "... VariableDeclaratorId" to complete
FormalParameterList
I don't know how to fix that. Can someone help?