gpt4 book ai didi

java - 尝试生成 2 个 vector ,其中包含 10 个 0-10 之间的随机数

转载 作者:行者123 更新时间:2023-12-01 17:06:02 25 4
gpt4 key购买 nike

我是新来的,我正在寻求有关此代码的帮助:

public static void main(String[] args) {
int o;
Vector v1 = new Vector();
Vector v2 = new Vector();
o = Integer.parseInt(JOptionPane.showInputDialog(null, "Welcome!\n"
+ "\n"
+ "Please select an Option: \n"
+ "1. Generate vectors A and B \n"
+ "2. Show vector's sum between elements \n"
+ "3. Sum both vectors \n"));
switch (o) {

case 1:
class v1 () {
int length = 10;
int[] series = new int[length];
for (int i = 1; i < length; i++) {
series[i] = (int) (Math.random() * 10);
}
JOptionPane.showMessageDialog(null, series[i]);
}
class v2 () {
int length = 10;
int[] series = new int[length];
for (int i = 1; i < length; i++) {
series[i] = (int) (Math.random() * 10);
}
JOptionPane.showMessageDialog(null, series[i]);
}
}
}

}

问题是,我只被允许使用方法、类、数组和对象。有任何想法吗?谢谢!

最佳答案

按如下方式声明 vector :

Vector<Integer> v1 = new Vector<>();

添加值

v1.add(1);

获取值

int b = v1.get(0); // b == 1

打印 vector

System.out.println(v1);

有关更多信息,请参阅Vector 。由于您的代码中存在其他严重的语法错误,请查看 The Java Tutorials寻求帮助。

关于java - 尝试生成 2 个 vector ,其中包含 10 个 0-10 之间的随机数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61465465/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com