在方法之间传递数组,并相应地访问它们

时间:2018-04-18 20:15:07

标签: arrays methods

我应该使用两种方法来保持阵列,然后两个阵列确定火箭队的胜率,休斯顿火箭队输掉的比赛的平均得分差异,以及休斯顿火箭队的最低得分和相应的比赛号码。我主要需要第一个帮助,我可以完成其他任务。我只是不知道如何从方法中传递数组。任何帮助都会有用,谢谢!

import java.util.Scanner;
public class MorenoJonathonRocketsStatistics
 {
public static void main(String[] args)
 {
 System.out.println("enter rockets game scores");
 int[] rockets = rocketsScore();
 System.out.println("enter opponents scores");
 int[] opponents = opponentsScore();
  int per = percent();
 System.out.println("game win percent"+per+" %");

}

public static int[] rocketsScore()
 {
 Scanner sc = new Scanner(System.in);
 int[] rocketsScore = new int[8];

 for(int i=0;i<rocketsScore.length;i++)
 {
 rocketsScore[i] = sc.nextInt();
}
 return rocketsScore;
}

 public static int[] opponentsScore()
 {
 Scanner sc = new Scanner(System.in);
 int[] opponentsScore = new int[8];

 for(int i=0;i<opponentsScore.length;i++)
  {
   opponentsScore[i] = sc.nextInt();
  }
return opponentsScore;

 }

 public static int percent(int[] array, int[] array2)
 {
  int[] rock = rocketsScore.length();
  int[] opp = opponentsScore.length();
  double percent=0;
  int w=0, l=0;
  for(int i=0; i<rocketsScore.length;i++)
   {
   if(rocketsScore[i]>opponentsScore[i])
  {
   w++;
   }
   else{
    l++;
   }
 }
 percent = w/l;
 return percent;
  }
}

1 个答案:

答案 0 :(得分:0)

要在方法中传递数组,您不需要在持有数组的变量旁边放置任何括号。所以,你可能想要这样做:

int per = percent(rockets, opponents);