-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
  • 26,308
  • 17
  • 56
  • 95

2 Answers2

0

to initialize array, use

temps = new int[] {...};
Ecto
  • 1,125
  • 1
  • 7
  • 13
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
  • 953
  • 6
  • 11