所以我大胆地认为错误正在发生,但我不明白它们为什么会发生。这对我来说没什么意义。
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"**
{
}
}发布于 2012-11-19 03:10:45
if(price=>0)这应该是:
if(price >= 0)注意>和=的顺序。>是第一个。
还有:- else(price==0)应该只是else,你不需要在你的else中添加条件。
发布于 2012-11-19 03:11:06
您的大于或等于排序错误。
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-19 03:12:04
在java中,“大于或等于”是>=。另外,对于第二个错误,您应该使用"else if",而不仅仅是“else”。
https://stackoverflow.com/questions/13443550
复制相似问题