gpt4 book ai didi

java - 缺少返回语句错误

转载 作者:行者123 更新时间:2023-12-01 06:46:22 24 4
gpt4 key购买 nike

我已经编写了一段代码,每当我尝试测试它时,都会收到一条错误消息:

"StreetAddress.java:62: missing return statement 

}"

这是代码:

public class StreetAddress
{
private String myStreet;
private String myCity;
private String myState;
private String myZip;

public StreetAddress( String street, String city, String state, String zip )
{
myStreet = street;
myCity = city;
myState = state;
myZip = zip;
}

public void setStreet( String street )
{
myStreet = street;
}

public String getStreet()
{
return myStreet;
}

public void setCity( String city )
{
myCity = city;
}

public String getCity()
{
return myCity;
}

public void setState( String state )
{
myState = state;
}

public String getState()
{
return myState;
}

public void setZIP( String zip )
{
myZip = zip;
}

public String getZIP()
{
return myZip;
}

public String mailingLabel()
{
System.out.println( getStreet() );
System.out.println( getCity() + ", " + getState() + " " + getZIP() );
}
}
}

我不知道哪里缺少 } 我已经检查了我的代码好几次了。请帮忙!

最佳答案

这个函数:

public String mailingLabel()
{
System.out.println( getStreet() );
System.out.println( getCity() + ", " + getState() + " " + getZIP() );
}

被声明返回一个字符串,但缺少 return 语句。要么使其无效,要么返回某些内容 - 无论其意图如何。

关于java - 缺少返回语句错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11387661/

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