[英]Arrays in string Rather than Int
I have an array I'm using but when I realized I needed to use Decimal Points in my code and Make it so that The array labels itself 我有一个正在使用的数组,但是当我意识到需要在代码中使用小数点并将其设置为使数组本身标记为
When printed, Like so: 打印时,像这样:
Enter rental for month [1]: 231.1 输入月份的租金[1]:231.1
Enter rental for month [2]: 321.3 etc. 输入[2]月份的租金:321.3,等等。
Scanner keyboardScanner = new Scanner(System.in);
int[] array;
array = new int[12];
// creates for loop
for (int i=0; i<12; i++)
{
System.out.println("Enter Rental for month[]");
array[i] = keyboardScanner.nextInt();
}
for (int i=0; i<array.length; i++)
{
System.out.println(array[i]);
}
Any help Is appreciated! 任何帮助表示赞赏! I just need to do the above two points, Thank you.
我只需要做以上两点,谢谢。
Scanner keyboardScanner = new Scanner(System.in);
double[] array = new double[12];
// creates for loop
for (int i=0; i<12; i++)
{
System.out.println("Enter Rental for month[" + i + "]"));
array[i] = keyboardScanner.nextDouble();
}
for (int i=0; i<array.length; i++)
{
System.out.println(array[i]);
}
Hope this helps :) 希望这可以帮助 :)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.