【发布时间】:2021-02-16 16:00:00
【问题描述】:
import java.util.Arrays;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int size = input.nextInt();
int[] grades = new int[size];
for(int i=0; i < size; i++){
int x = input.nextInt();
grades[i] = x; **<<<<<< When i use this one i get the correct answer and i can input some numbers and they show up in a array**
x = grades[i]; **<<<<<< However here i input my numbers but the array shows up as zeros only. Why?**
}
System.out.println(Arrays.toString(grades));
}
【问题讨论】:
-
=不是数学上的等号,而是赋值。A = B的意思是“给AB的值”。这不是对称操作。 -
赋值总是FROM右边TO左边。如果您的问题不同,那么我不明白,请对问题本身添加一些评论。
-
试试
myvar = 3和3 = myvar看看会发生什么...
标签: java arrays for-loop arraylist integer