Me and a friend are trying to do an assignment for our Computer Science class, and we're given a set of numbers that we put in a 7 column 6 row grid
we're currently stuck on finding a diagonal pattern, this is the code we attempted to use to find a diagonal pattern in the grid:
//#Diagonal(//) Pattern
counter = 0;
number = 0;
for (int i = 0; i < arr.length - 3; i++)
{
for (int j = 0; j < arr[i].length - 3 ; j++)
{
if ( (arr[j][i] == arr[j][i + 1]) && (arr[j][i] == arr[j+ 3][i]) && (arr[j + 2][i] == arr[i][j]) )
{
counter = 1;
number = arr[i][j];
}
else
{
System.out.println("I love Emilia.");
}
}
}
if (counter == 1)
{
System.out.println("The following array has four consecutive " + number + "'s in a
diagonal (//) pattern:");
System.out.println();
//Prints out the array.
for (int i = 0; i < arr.length; i++)
{
for (int j = 0; j < arr[i].length; j++)
{
System.out.print(arr[i][j] + " ");
}
System.out.println();
}
}
Any help would be appreciated, thank you!
Aucun commentaire:
Enregistrer un commentaire