public String checkIn(Book b) {
for (int i = 0; i < books.length; i++) {
if (b.equals(books[i])) {
if (checkedOut[i] > 0) {
checkedOut[i]--;
return "Checked in!";
}
else {
return "All of our copies are already checked in.";
}
}
else {
return "Book not found.";
}
}
}
}
最后一个花括号是我得到错误的地方。奇怪的是它建议我删除它但它仍然发出错误。
有什么想法吗?
答案 0 :(得分:1)
几个错误。
1。)One curly brace is extra
在最后。
2。)同时在功能结束处添加return statement
。
答案 1 :(得分:0)
你有一个太多的牙箍。删除最后一个。我建议格式化您的代码,因为它将使您更容易阅读和修复此类问题。
public String checkIn(Book b){
for(int i = 0; i < books.length; i++){
if(b.equals(books[i])){
if(checkedOut[i] > 0){
checkedOut[i]--;
return "Checked in!";
}else{
return "All of our copies are already checked in.";
}
}else{
return "Book not found.";
}
}
return "";
}
答案 2 :(得分:0)
使用以下代码检查
public String checkIn(Book b)
{
for (int i = 0; i < books.length; i++)
{
if (b.equals(books[i]))
{
if (checkedOut[i] > 0)
{
checkedOut[i]--;
return "Checked in!";
}
else
{
return "All of our copies are already checked in.";
}
}
else
{
return "Book not found.";
}
}
}
答案 3 :(得分:0)
您的代码
public String checkIn(Book b)
{
for (int i = 0; i < books.length; i++)
{
if (b.equals(books[i]))
{
if (checkedOut[i] > 0)
{
checkedOut[i]--;
return "Checked in!";
}
else
{
return "All of our copies are already checked in.";
}
}
else
{
return "Book not found.";
}
}
return "something";
}