java - remove unwanted consecutive char set if in argument(String) and return the filtered argument, else return original argument string
问题描述
the code below throws the error " 'i' cannot be resolved to a variable ", any explanations please??
static String abc(String str) {
String[] sarr = str.split("");
String[] newsarr = new String[sarr.length-3];
String s = "";
for (int i = 1; i < sarr.length; i++); {
if ((sarr[i] == "a") && (sarr.length >= i+3)) {
if ((sarr[i+1] == "b") && (sarr[i+2] == "c")) {
newsarr[0] = sarr[0];
for (int x = 1; x < i; x++) {
newsarr[i] = sarr[i];
}
for (int y = i+3; y < newsarr.length; y++) {
newsarr[y-3] = sarr[y];
}
} else {}
} else {}
}
for (String o : newsarr) {
s += o;
}
return s;
}
解决方案
删除第一个 for 循环上的分号会产生奇迹。
分号结束 for 语句和 i 的范围。
推荐阅读
- php - 删除项目时购物车页面为空
- c# - 如何使用 Binance API 计算特定硬币的订单集合花费了多少钱?
- javascript - 从 Shiny DT 中的单选按钮中提取用户输入值到数据框或列表中
- javascript - Vue3编程路由在chrome中不起作用
- rabbitmq - AMQP 消息属性未发布到 RabbitMQ 集线器
- python - 在 Visual Studio Code 中调试由嵌入式 Python 运行的 Python 代码
- python - Python:GEKKO 求解代数微分方程的快速替代方案
- flutter - 如何在 Parse Server 上使用 google 登录
- javascript - jQuery 在 Circle Bars 插件上将 countup 方法更改为倒计时
- python - 线性内存增加与调用 Model.fit 的次数成正比