Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.
public static int whichShip(int[][] array, int row, int col){
//find which ship got hit (find coordinate in compBoard array, and return the index)
int i = 0;
for (i = 0; i < array.length; i++){
for (int j = 0; j < array[i].length; j++){
if (array[i] == row && array[i][j] == col){
return i;
}
}
}
}
public static int whichShip(int[][] array, int row, int col){
//find which ship got hit (find coordinate in compBoard array, and return the index)
int i = 0;
for (i = 0; i < array.length; i++){
for (int j = 0; j < array[i].length; j++){
if (i== row && j == col){
return arry[i][j];
}
}
}
}
array[i] == row
beacuse array[i] is one-dimensional int array int[]
public static int whichShip(int[][] array, int row, int col){
//find which ship got hit (find coordinate in compBoard array, and return the index)
int result = 0;
for (int i = 0; i < array.length; i++){
for (int j = 0; j < array[i].length; j++){
if (i == row && array[i][j] == col){
result = i;
}
}
}
return result;
}
int value = 12;
Coordinates coords = getCoords(array, value);
System.out.println(coords.getRow() + " ," + coords.getColumn());
public Coordinates getCoords(int [][] array, int value){
for(int j=0;j<array.length; j++){
for(int i=0; i<array[j].length; i++){
if(array[j][i] == value){
Coordinates coords = new Coordinates(j, i);
return coords;
}
}
}
return null;
}
}
public class Miscellaneous {
static int[][] array = new int[][]{{1,2,3},{4,5,6} };
public static Coordinates getCoords(int [][] array, int value){
for(int j=0;j<array.length; j++){
for(int i=0; i<array[j].length; i++){
if(array[j][i] == value){
Coordinates coords = new Coordinates(j, i);
return coords;
}
}
}
return null;
}
public static void main(String[] args) {
int value = 6;
Coordinates coords = getCoords(array, value);
System.out.println(coords.getRow() + " , " + coords.getColumn());
}
}
class Coordinates {
int row;
int col;
public Coordinates(int row, int col){
this.row = row;
this.col = col;
}
public int getRow() { return row; }
public int getColumn() { return col; }
}
1 , 2
public static int whichShip(int[][] array, int row, int col){
//find which ship got hit (find coordinate in compBoard array, and return the index)
int result = 0;
for (int i = 0; i < array.length; i++){
for (int j = 0; j < array[i].length; j++){
if(array[i][j] == (row * 10) + col){
result = i;
break;
}
}
}
return result;
}
If you are experiencing a similar issue, please ask a related question
Join the community of 500,000 technology professionals and ask your questions.