[英]Why do I keep on getting this error “error: unexpected type”
編譯此代碼時出現相同的錯誤。 我想知道如何成功添加“出租天數”和“出租率”。 請幫忙。
Tractor.java:83: error: unexpected type
RentalDays + RentalRate = RentalProfit;
^
required: variable
found value
1 error
碼:
import java.util.*;
public class Tractor
{
private String name;
private int VehicleID;
private int RentalRate;
private int RentalDays;
public int setRentalRate(int RentalRate)
{
if (RentalRate <= 0 || RentalRate > 100000)
{
return -1;
}
else
{
return this.RentalRate;
}
}
public int getRentalRate()
{
return this.RentalRate;
}
public int setRentalDays(int RentalDays)
{
if (RentalDays <= 0 || RentalDays > 365)
{
return -1;
}
else
{
return this.RentalDays;
}
}
public int getRentalDays()
{
return this.RentalRate;
}
public int RentalProfit(int RentalRate, int RentalDays)
{
int RentalProfit;
RentalDays + RentalRate = RentalProfit;
}
}
只需編寫代碼即可添加。
public int RentalProfit(int RentalRate, int RentalDays)
{
return RentalDays + RentalRate;
}
RentalDays + RentalRate = RentalProfit;
之所以無效,是因為=
運算符的左手大小應為要分配的變量,而不是加法的結果。
您的意思是RentalProfit = RentalDays + RentalRate;
?
更改
int RentalProfit;
RentalDays + RentalRate = RentalProfit;
至
return RentalDays + RentalRate;
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.