gpt4 book ai didi

Java 类型错误的非法开始

转载 作者:行者123 更新时间:2023-11-30 04:50:21 26 4
gpt4 key购买 nike

我在第一个嵌套 if 语句中遇到非法开始类型错误,查看了类似的问题后,我知道这通常是由错位的大括号引起的,但是,我看不到。有人可以帮忙吗?

public class Journey
{
private int date;
private double time;
private int busNumber;
private int journeyType;
public static double dayCharge;
public static final double maxDayCharge = 3.50;
public static double weekCharge;
public static final double maxWeekCharge = 15;
public static double monthCharge;
public static final double maxMonthCharge = 48;
private int journeyId;
private static int numberOfJourneys;
private double costOfJourney;

public int getDate(){
return date;
}
public Double getTime(){
return time;
}
public int getBusNumber(){
return busNumber;
}
public double journeyCost(journey reqJourney){
if (journeyType = 1){ //this is where the error occurs
if (dayCharge =< 2.50)
{
costOfJourney = 1;
}
else
{
costOfJourney = maxDayCharge-dayCharge;
}

}
else if (journeyType = 2)
{
if (dayCharge =< 1.80)
{
costOfJourney = 1.70;
}
else
{
costOfJourney = maxDayCharge-dayCharge;
}
}
else if (journeyType = 3)
{
if (dayCharge =< 1.60)
{
costOfJourney = 1.90;
}
else
{
costOfJourney = maxDayCharge-dayCharge;
}

}
return costOfJourney;
}
public boolean isInSequence(journey reqJourney){
journey prevJourney = jArray.get(jArray.size()-1);
if (prevJourney.date > reqJourney.date)
{
return false;
}

}
}

最佳答案

您需要使用==来测试相等性。 = 是赋值运算符。

Oracle有好tutorial docs解释 Java 运算符。

相关说明中,Object.equals()== 之间也存在重要区别,其他 Stack Overflow 问题(如 this one)对此进行了详细介绍。 。但是,当像您一样比较原始类型时, == 就是您想要的。

关于Java 类型错误的非法开始,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9997096/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com