我想要一个程序,它首先询问数组的大小,然后询问元素。数组的大小是 int,存储的值是 double。像这样:How many numbers? 5 // 5 is user inputPlease type the numbers:1,111411,45213The numbers in reverse order are:3.0 21.0 11.45 4.0 1.111我的问题是,如何询问尺寸和元素?提前致谢!
1 回答

蓝山帝景
TA贡献1843条经验 获得超7个赞
使用下面的代码。
Scanner sc = new Scanner(System.in);
int arraysize=sc.nextInt();
double[] doubleArray = new double[arraysize];
for(int i=0; i<arraysize; i++){
doubleArray[i] = sc.nextDouble();
}
添加回答
举报
0/150
提交
取消