小编Nei*_*nes的帖子

打印ArrayList时出现冗余结果

   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)

java arraylist

0
推荐指数
1
解决办法
31
查看次数

无法使PrintWriter工作

我正在为游戏创建一个保存游戏文件,但我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但它不起作用.

java io printwriter

0
推荐指数
1
解决办法
63
查看次数

标签 统计

java ×2

arraylist ×1

io ×1

printwriter ×1