java - 在字符串中查找重复的字符 - 但没有得到预期的结果 - 作为一个尝试学习的初学者 - 请有人帮我解决
问题描述
谁能帮助我以下程序中的错误是什么。实际我试图找到重复的字符,如果它重复布尔重复应该是真的。但是当我尝试调试时,它没有找到重复项。
void main() {
String word = "abcda";
for (int i = 0; i < word.length(); i++) {
char ch = word.charAt(i);
boolean repeat1 = false;
for (int j = i + 1; j < word.length(); j++) {
if (ch == word.charAt(j)) {
System.out.println("repeated " + ch);
repeat1 = true;
break;
}
if(repeat1==false) {
System.out.println("Not repeated " + ch);
break;
}
}
}
实际结果:
Not repeated a
Not repeated b
Not repeated c
Not repeated d
预期结果:我应该得到结果
repeated a
Not repeated b
Not repeated c
Not repeated d
解决方案
推荐阅读
- javascript - 如何在玩笑中模拟/监视 useState 钩子?
- ios - 运行应用程序时找不到单元标识符
- networking - 网卡的MAC地址如何用于设备之间的通信?
- python - 无法在 Python 中读取二进制文件
- python - Python OpenCV LoadDatasetList,最后两个参数是什么?
- javascript - 如何在角度 9 中动态删除组件?
- html - 使用 emmet 缩写创建颜色
- python - Python返回适合设置参数的项目列表
- java - 如何快速找到给出最大值的点?请使用 Java 或 C++ 代码
- octave - Octave:根据向量设置矩阵值