gpt4 book ai didi

java - xyzMiddle—我认为我没有遗漏任何东西,那么这个错误意味着什么?

转载 作者:行者123 更新时间:2023-12-01 19:20:38 24 4
gpt4 key购买 nike

Given a string, does "xyz" appear in the middle of the string? To define middle, we'll say that the number of chars to the left and right of the "xyz" must differ by at most one.

这是我对这个练习的看法:

public boolean xyzMiddle(String str) {
int indexXYZ = str.indexOf("xyz");
int toLeft = indexXYZ;
int toRight = str.length() - (indexXYZ + 3);
int val = toRight - toLeft;
if(Math.abs(val) <= 1))
return true;
else return false;
}

我不知道为什么,但我不断收到一条编译错误消息,上面写着“缺少'}'或非法的表达式开始”,但我不认为我错过了任何东西。有人可以帮我找出我的错误吗?

最佳答案

public boolean xyzMiddle(String str) {
int indexXYZ = str.indexOf("xyz");
int toLeft = indexXYZ;
int toRight = str.length() - (indexXYZ + 3);
int val = toRight - toLeft;
if(Math.abs(val) <= 1)
return true;
else
return false;
}

if 部分存在结构错误

关于java - xyzMiddle—我认为我没有遗漏任何东西,那么这个错误意味着什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59359882/

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