0
我想获取字符串和整数的值,所以我可以利用它。我已经采取了价值,并试图存储在数组中,然后打印该值。出于某种原因,我没有正确地获取字符串的值。你能帮我把我的代码改正吗?字符串数组没有得到正确的值
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int r = sc.nextInt();
int [] numbers = new int[r];
String names[] = new String[r];
for(int i=0; i<r; i++){
numbers[i] += sc.nextInt();
names[i] += sc.next();
}
System.out.println(Arrays.toString(numbers));
System.out.println(Arrays.toString(names));
}
Output : [2,2]
[nullAA, nullBB]
而且如何获得打印语句后两个数组的索引。
由于其工作正常。我需要一个循环来获取索引或其他方式也存在 –
@shankysingh是的,请参阅编辑。 – Eran
谢谢。因此,我是初学者,有点混乱。 10分钟后我会接受答案。再次感谢。 –