英文:
What is wrong with the way I have initialized 'temps'?
问题
public class ArrayMethod {
static int[] temps;
public static void create() {
temps = new int[]{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.
英文:
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.
答案1
得分: 0
用以下代码初始化数组:
temps = new int[] {...};
英文:
to initialize array, use
temps = new int[] {...};
答案2
得分: 0
用以下方式初始化你的数组。你现在的使用方式会导致编译时错误,因为数组常量只能在初始化器中使用。
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
temps = new int[]{28, 27, 28, 21, 21, 19, 18, 29, 31, 24};
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论