import java.util.Scanner;
class player_test {
public static void main(String[] args) {
Scanner s_in = new Scanner(System.in);
Scanner i_in = new Scanner(System.in);
class player {
String player_name;
String player_class;
String player_race;
int player_STR = 10;
int player_DEX;
int player_CON;
int player_WIS;
int player_INT;
int player_CHA;
}
int tempDex = new player(player_STR);
System.out.println(tempDex);
}
}
好的,所以我對Java很新,我認爲這比我做的更基本。所以我有對象玩家,它將玩家的核心數據存儲在其中,但是如何在整個代碼中的其他位置調用這些變量?至少讓它打印出球員的實力得分?試圖打印存儲在另一個對象中的變量java
你可以做'的System.out.println(tempDex。 player_STR);'或者使用你的IDE向'Player'添加'toString()'方法,因爲你不需要在所有字段名稱中添加'player_'。 –
你應該嘗試爲類和'camelCase'使用'PascalCase'作爲變量/屬性/函數名稱。當然,這是一種文體選擇,但這往往是命名事物最常見的方式。 –
小心:int tempDex =新玩家(player_STR);你將一個玩家類分配給一個int類型 –