【发布时间】:2021-12-21 21:34:52
【问题描述】:
我正在尝试从一个数组中的 2 个不同变量中获取 2 个不同的值并将它们相乘,然后将它们相加;但是,当我稍后尝试使用该代码时,会弹出一个错误。
我的代码:
import java.util.ArrayList;
class HW {
public static void main(String[] args) {
int [] uno = {3, 5};
ArrayList<Integer> obj1 = new ArrayList<Integer>();
int a = (uno[0]);
int b = (uno[1]);
}
public static void man(String[] args) {
ArrayList<Integer> obj2 = new ArrayList<Integer>();
int [] dos = {7, 6};
int a1 = (dos[0]);
int b1 = (dos[1]);
}
public static void an(String[] args) {
int x = ((uno[0]) * b1);
int y = (a1 * b);
System.out.println(x + y);
}
}
【问题讨论】: