好的,所以我正在做这个项目,要求我有一个字符串的第一个和最后一个setters出现与他们之间计算的数字和输出。我试过重新调整一些反向字符串代码,但我无法让输出显示在我的IDE中。计数字母之间的第一个和最后 - Java
任何人都可以看看我的代码,并提出一些建议?
public static void main(String[] args) {
String countWord;
countWord = JOptionPane.showInputDialog(null,
"Enter the string you wish to have formatted:");
}
static String countMe(String countWord) {
int count = 1;
char first = countWord.charAt (0);
char last = countWord.charAt(-1);
StringBuilder word = new StringBuilder();
for(int i = countWord.length() - 1; i >= 0; --i)
if (countWord.charAt(i) != first) {
if (countWord.charAt(i) != last) {
count++;
}
}
return countWord + first + count + last;
}
}
什么是“字符串二传手”? – Rainbolt
我想你想char last = countWord.charAt(countWord.length - 1);,为什么不只是使用countWord.length - 2来得到中间的字符数? –
我不明白你想要做什么,也不知道你有什么问题。你能否澄清两个? – Keppil