Java只打印了我的String数组中的一半元素

时间:2017-02-23 19:42:21

标签: java arrays string printing

我正在尝试打印出名为Resources的字符串数组的每个元素以及它之前的语句,以及之后的整数。

它应该打印出来:

  

收集分配器Wood 10

首先,这是我的代码:

private String[] Resources =  { "Explosives", "Animal Fat", "Cooked Fish",
        "Raw Fish", "Low Grade Fuel", "Granola Bar", "Gun Powder", "Hemp Clone", "Hemp Seed",
        "High Quality Metal Ore", "Burned Human Meat", "Cooked Human Meat", "Raw Human Meat",
        "Spoiled Human Meat", "Leather", "Burnt Bear Meat", "Bear Meat Cooked", "Bear Meat",
        "Burned Pork", "Cooked Pork", "Pork", "Burned Wolf Meat", "Cooked Wolf Meat", 
        "Raw Wolf Meat", "Spoiled Wolf Meat", "Metal Fragments", "Metal Ore","High Quality Metal",
        "Minnows", "Mushroom", "Paper", "Pumpkin", "Pumpkin Plant Clone", "Pumpkin Seed",
        "Research Paper", "Salt Water", "Human Skull", "Wolf Skull", "Small Trout", "Small Water Bottle",
        "Stones", "Sulfur", "Sulfur Ore", "Targeting Computer", "Water", "Water Jug", "Wood", "Apple", 
        "Rotten Apple", "Battery - Small", "Black Raspberries", "Blueberries","Bone Fragments", 
        "Cactus Flesh", "Can of Beans", "Empty Can Of Beans", "Can of Tuna", "Candy Cane", "CCTV Camera", 
        "Charcoal", "Burned Chicken", "Cooked Chicken", "Raw Chicken Breast", "Spoiled Chicken", "Chocolate Bar",
        "Cloth", "Coal :(", "Corn", "Corn Clone", "Corn Seed", "Crude Oil" };

private int multiplier;

public Miserum(int value)
{
    // initialise instance variables
    multiplier = value;
}

public void DoThis(){
    String result = " ";
    for(int x = 0; x < Resources.length; x++){
        result = "gather.rate dispenser " + Resources[x] + " " + multiplier;
        System.out.println(result);
    }
}

所以String[] Resources中有大约71个元素。

当我运行DoThis()方法时,它会打印大约46个元素,它甚至不会从头开始,它从

开始
  被宠坏了的狼肉。

为什么会这样?它完全占据了第一个元素,并从中间开始打印。

我不认为这是我的代码所要做的,但显然有错误。

如果您有更好的方法来执行此操作/修复我的解决方案,请将豆子溢出。

*我正在使用BlueJ IDE

0 个答案:

没有答案