Pet*_*r F -1 java double int file
在我的程序中,我从一个文本文件加载一些自定义变量来使用.这是执行此操作的方法.
public int[] getGameSettings() {
String[] rawGame = new String[100];
String[] gameSettingsString = new String[6];
int[] gameSettings = new int[6];
int finalLine = 0;
int reading = 0;
try{
// Open the file that is the first
// command line parameter
FileInputStream fstream = new FileInputStream("gameSettings.txt");
BufferedReader br = new BufferedReader(new InputStreamReader(fstream));
String strLine;
//Read File Line By Line
int line = 0;
while ((strLine = br.readLine()) != null) {
// Store it
rawGame[line] = strLine;
line++;
}
//Close the input stream
in.close();
reading = line;
}catch (Exception e){//Catch exception if any
System.err.println("Error: " + e.getMessage());
}
for (int a = 0; a < reading; a++) {
if (!rawGame[a].substring(0,1).equals("/")) {
gameSettingsString[finalLine] = rawGame[a];
finalLine++;
}
}
for (int b = 0; b < finalLine; b++) {
gameSettings[b] = Integer.parseInt(gameSettingsString[b]);
}
return gameSettings;
}
Run Code Online (Sandbox Code Playgroud)
我从另一个类调用该方法并将数组保存为gameSettings,然后执行以下操作:
contestedMovementPercent = (gameSettings[1]/100);
Run Code Online (Sandbox Code Playgroud)
有争议的运动总是显示为0.0,即使我打印gameSettings [1]它出现了它应该是什么.contestedMovementPercent是一个双倍.gameSettings是两个类中的int数组.
我需要做某种演员吗?我认为int可以像这样使用.