import java.util.ArrayList;
import java.util.List;
public class Apple {
private static String color;
private static int weight;
public Apple(String color, int weight){
this.color = color;
this.weight = weight;
}
public int getWeight(){
return weight;
}
public String getColor(){
return color;
}
public interface AppleFormatter{
String accept(Apple a);
}
public static class AppleFancyFormatter implements AppleFormatter{
public String accept(Apple apple){
String characteristic = apple.getWeight() > 150 ? "heavy" : "light";
return "A " + characteristic + " " + apple.getColor() + " apple"; …
Run Code Online (Sandbox Code Playgroud) 我正在为游戏创建一个保存游戏文件,但我PrintWriter
只是覆盖了文件而不是我需要的数字.
这是代码:
public void fileWriter() throws FileNotFoundException {
PrintWriter print = new PrintWriter(new File("C:\\Users\\john\\Desktop\\stats.txt"));
print.print(String.valueOf(this.swordNumber) + " ");
print.print(String.valueOf(this.shieldNumber) + " ");
print.print(String.valueOf(this.monstersDefeated) + " ");
print.print(String.valueOf(this.damageDealt));
}
Run Code Online (Sandbox Code Playgroud)
我已经尝试了一切来打印这些变量,String.valueOf
但它不起作用.