我写了这段代码:
Scanner askPrice = new Scanner(System.in);
for(double i = 0 ; i < 3; i++);
{
double totalInitial = 0.00;
System.out.println("Enter the price for your item. "
+ "Press enter after each entry. Do not type the '$' sign: ") ;
double price1 = askPrice.nextDouble(); //enter price one
double price2 = askPrice.nextDouble(); //enter price two
double price3 = askPrice.nextDouble(); //enter price three
double total = ((totalInitial) + (price1) + (price2) + (price3));
我想将 for 循环更改为 while 循环,以询问用户一个项目的价格(双精度输入),直到一个哨兵值。我怎样才能做到这一点?我知道我已经设置了三个迭代,但是我想修改没有预设迭代次数的代码。任何帮助,将不胜感激。