我如何根据用户输入实例化一个数组

时间:2016-04-05 16:15:18

标签: java arrays instantiation

我对如何使用来自用户的输入来实例化数组感到困惑,我相信它应该在这里的注释旁边     import java.util.Scanner;

public class Sales
{
  public static void main(String[] args)
  {
    int[] sales;

    sales = getSales();
    printSales(sales);
    printSummary(sales);
  }

  private static int[] getSales()
  {
    Scanner input = new Scanner(System.in);
    int[] temp;

    System.out.print("Enter the number of salespeople: ");
    temp = _____________;   // RIGHT HERE  

1 个答案:

答案 0 :(得分:2)

你应该写一些类似的东西:

temp = new int[input.nextInt()];