我如何初始化 ‘temps’ 有什么问题吗?

huangapple go评论96阅读模式
英文:

What is wrong with the way I have initialized 'temps'?

问题

  1. public class ArrayMethod {
  2. static int[] temps;
  3. public static void create() {
  4. temps = new int[]{28, 27, 28, 21, 21, 19, 18, 29, 31, 24};
  5. }
  6. }
  7. I am required to use 'temps' in other methods but am getting a variety of errors.
英文:
  1. public class ArrayMethod {
  2. static int[] temps;
  3. public static void create() {
  4. temps = {28, 27, 28, 21, 21, 19, 18, 29, 31, 24};
  5. }
  6. }

I am required to use 'temps' in other methods but am getting a variety of errors.

答案1

得分: 0

用以下代码初始化数组:

  1. temps = new int[] {...};
英文:

to initialize array, use

  1. temps = new int[] {...};

答案2

得分: 0

用以下方式初始化你的数组。你现在的使用方式会导致编译时错误,因为数组常量只能在初始化器中使用。

  1. temps = new int[]{28, 27, 28, 21, 21, 19, 18, 29, 31, 24};
英文:

initialize your array as below. The way you are using would give compile time error because array constants can only be used in initializers

  1. temps = new int[]{28, 27, 28, 21, 21, 19, 18, 29, 31, 24};

huangapple
  • 本文由 发表于 2020年5月5日 21:47:44
  • 转载请务必保留本文链接:https://go.coder-hub.com/61614717.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定