Java 使用并行数组和用户输入

Java 使用并行数组和用户输入,java,arrays,jgrasp,Java,Arrays,Jgrasp,对于我的程序,我必须创建一系列方法,但我坚持要启动它。基本上是一个存储树木类型和种子数量的程序。我有一个数组中的树列表,并且想把每棵树的种子数放在一个并行数组中,我觉得我采取了正确的步骤,但逻辑并不正确 import javax.swing.JOptionPane; public class seedFarmer { public static void main(String[] args) { } public static int getNumEachTre

对于我的程序,我必须创建一系列方法,但我坚持要启动它。基本上是一个存储树木类型和种子数量的程序。我有一个数组中的树列表,并且想把每棵树的种子数放在一个并行数组中,我觉得我采取了正确的步骤,但逻辑并不正确

import javax.swing.JOptionPane;

public class seedFarmer {
   public static void main(String[] args) {
         }
   public static int getNumEachTree() { 
      String[] treeTypes = {"Fir" , "Pine" , "Spruce"};
      int[] numTrees = new int[treeTypes.length];
      int numofTrees = getNumEachTree();

       for (int index = 0; index < numTrees.length; index++) {

             numTrees[index] = Integer.parseInt(JOptionPane.showInputDialog("Enter the number of seeds you want to plant for: " + treeTypes[index]));
      }
     return numTrees;
    }
  }
import javax.swing.JOptionPane;
公营种植者{
公共静态void main(字符串[]args){
}
公共静态int getNumEachTree(){
String[]treeTypes={“枞树”、“松树”、“云杉”};
int[]numTrees=newint[treeTypes.length];
int numofTrees=getNumEachTree();
for(int index=0;index
您的主要问题在于:

   public static int getNumEachTree() { 
      String[] treeTypes = {"Fir" , "Pine" , "Spruce"};
      int[] numTrees = new int[treeTypes.length];
      int numofTrees = getNumEachTree();                  <--HERE
public static int getNumEachTree(){
String[]treeTypes={“枞树”、“松树”、“云杉”};
int[]numTrees=newint[treeTypes.length];
int numofTrees=getNumEachTree();