Overview
more information it's will help you also in homework
public class BishopMoves {
public static int numBishopMoves(String square) {
square.toUpperCase();
// Convert from uppercase letter to integer representation of column
// number
int col = square.charAt(0) - 64;
// Convert from character to integer representation of row number
int row = square.charAt(1) - 48;
int numMoves = 0;
for (int newCol = 1; newCol < 8; newCol++) {
int offset = newCol - col;
int newRowAbove = row + offset;
if (newRowAbove >= 1 && newRowAbove <= 8) {
numMoves++;
System.out.println((char) (newCol+64)
+ (char) (newRowAbove+48));
}
int newRowBelow = row - offset;
if (newRowBelow >= 1 && newRowBelow <= 8) {
numMoves++;
System.out.println((char) (newCol+64)
+ (char) (newRowBelow+48));
}
}
return numMoves;
}
}