-2
public class ArrayMethod {

    static int[] temps;

    public static void create() {
         temps = {28, 27, 28, 21, 21, 19, 18, 29, 31, 24};

    }
}

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

Federico klez Culloca
  • 24,336
  • 15
  • 57
  • 93

2 Answers2

0

to initialize array, use

temps = new int[] {...};
Ecto
  • 1,095
  • 1
  • 7
  • 12
0

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

temps = new int[]{28, 27, 28, 21, 21, 19, 18, 29, 31, 24};
Gaurav Dhiman
  • 823
  • 5
  • 10