0

所以我加粗了错误是否正在发生,但我不明白它们为什么会发生。这对我来说没有意义。

    for(int i = 1; i < Array.getLength(purchases);i++)
    {
        System.out.print("\n");
        System.out.print("Enter a price for item #"+i+": $");
        double temp3=input.nextDouble();
        double price=temp3;

            if(price=>0) **<==it wont let me have both = and >**
            {
                total=total+price;
                double temp1=total*100;
                int temp2=(int)temp1;
                total=temp2/100.0;
        System.out.print("That was $"+price+". Your total is $"+total);
            }
       else(price==0) **<=="The left-hand side of an assignment must be a variable"**
            {

            }
    }
4

3 回答 3

2
if(price=>0)

这应该是: -

if(price >= 0)

>注意和的顺序=>先来。

而且: -else(price==0)应该只是else,你不需要在你的else.

于 2012-11-18T19:10:44.727 回答
1

你的大于或等于排序是错误的。

if(price=>0)

应该

if(price>=0)

正确的顺序是使用>=

 else(price==0)

应该

 else if(price<0) //should be less than zero , because you are already checking if price is >=0 in your if.

否则就足够

嵌套 if-else 语法

  if(somecond){

   }
   else if(somecond){
    }
   else{ // you don't mention any condition for else, as it would be the last condition.

    }
于 2012-11-18T19:11:06.367 回答
0

In java, "greater than or equal to" is >=. Also, for the second error, you should have "else if", not just "else."

于 2012-11-18T19:12:04.027 回答