我一直在尋找一段時間,但人們似乎在我前面的象棋前waaaaay。我想要做的是在課堂上有一種方法來解決瓦片的顏色,但我的顏色不斷變成「空白」。使用一種方法來解決國際象棋瓷磚顏色
import java.util.Scanner;
公共類ChessTileTest {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
String tileColour;
chessTile test = new chessTile();
System.out.print(" Enter chess move : ");
String move = in.next();
tileColour = test.setColour(move);
System.out.println(tileColour);
}
}
公共類chessTile { 私人串色; 私人字符串地址;
public chessTile(){
}
public String setColour(String move){
char letter;
int number;
letter = move.charAt(0);
number = move.charAt(1);
if((letter=='a'||letter=='c'||letter=='e'||letter=='g')&&(number/2==1)){
colour = "Black";
}
else if((letter=='a'||letter=='c'||letter=='e'||letter=='g')&&(number/2==0)){
colour = "white";
}
else if((letter=='b'||letter=='d'||letter=='f'||letter=='h')&&(number/2==1)){
colour = "white";
}
else if((letter=='b'||letter=='d'||letter=='f'||letter=='h')&&(number/2==0)){
colour = "Black";
}
return colour;
}
}
你能分享chessTile類? (順便說一句,如果java的類名應該是大寫) – FriedSaucePots
哦,是的,謝謝:) –