我如何将输入添加到“valor2” ? - 爪哇
我刚开始学习java,有人知道,我怎样才能问“输入你的值”,并将 id 添加到 double[] valor2 ?
class test { // body start
public static void main(String [] args) {
double[] valor2 = {15, 4864, 4, 21}; // here is my doubt
for (int a=0; a<valor2.length; a++){
System.out.format("%s %d: O valor deste item é %10.2f %s%n", "Item", a+1, valor2[a], "reais");
}
}
}
I just started to learn java, someone knows, how can i ask like "Type your values", and add id to the double[] valor2 ?
class test { // body start
public static void main(String [] args) {
double[] valor2 = {15, 4864, 4, 21}; // here is my doubt
for (int a=0; a<valor2.length; a++){
System.out.format("%s %d: O valor deste item é %10.2f %s%n", "Item", a+1, valor2[a], "reais");
}
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用
扫描仪
进行输入。请注意,这是一个非常简单的示例:1)或其他替代。 2)
double[]
的大小在源代码中硬编码为 4。如果您想动态更改值
大小,请使用 ArrayListScanner
也可以接受int
、float
、String
,请在您的男女混合课程中尝试一下。 3)System.out.format
可以替换为System.out.print()
和String.format(format, ...args) 的组合
,更加灵活。Use a
Scanner
for inputs.Note that this is a very simple example: 1) The size of the
double[]
is hardcoded in the source as 4. If you want to dynamically change thevalues
's size, useArrayList<Double>
or some other instead. 2)Scanner
can takeint
,float
,String
as well, try them in your coed. 3)System.out.format
can be replaced by the combination ofSystem.out.print()
andString.format(format, ...args)
, which is more flexible.