这是我当前的代码:如何显示INTS的列表,并显示总成本
public static void Costs(float[] args) {
Scanner Costs = new Scanner(System.in);
String Item1Cost;
System.out.print("Enter the cost of Item 1 £");
Item1Cost = Costs.next();
String Item2Cost;
System.out.print("Enter the cost of Item 2 £");
Item2Cost = Costs.next();
String TotalCost;
TotalCost = Item1Cost + ", " + Item2Cost;
System.out.println("The cost of each of your items in order is: " + TotalCost);
}
我想,这样它获得一个int形成用户并显示所有价格去改变它,也合计它们。
当尝试我自己我用这个,我可以得到“成本”存储他们在一个字符串,并显示他们,但我不能让这段代码的总计。我想知道是否有人可以帮我一把。我相信答案非常简单,但我对java相当陌生,我只是不能想出解决方案。
请使用Java命名约定;即变量名称应以小写字母开头。 – arshajii
在你为什么不那种情况下接受整只使用'Costs.nextInt()' – exexzian