Java-在
我不认为我对-1在这段代码中工作的原因有明确的理解:它只是一个允许程序继续运行的位置标记吗?任何帮助或指导都将不胜感激Java-在,java,string,char,indexof,Java,String,Char,Indexof,我不认为我对-1在这段代码中工作的原因有明确的理解:它只是一个允许程序继续运行的位置标记吗?任何帮助或指导都将不胜感激 public class RemovingChar { public static void main(String[]args) { String str = "Looking out the window of my small apartment"; String remove = "aeiou"; S
public class RemovingChar {
public static void main(String[]args)
{
String str = "Looking out the window of my small apartment";
String remove = "aeiou";
String x = " ";
for(int i=0; i<str.length(); i++)
{
char c = str.charAt(i);
if(remove.indexOf(c) == -1)
{
x+= c;
}
}
System.out.print(x);
}
}
公共类RemovingChar{
公共静态void main(字符串[]args)
{
String str=“从我的小公寓的窗户向外看”;
String remove=“aeiou”;
字符串x=“”;
对于(int i=0;i
如果此字符串中没有出现此类字符,则返回-1。
如果此字符串中未出现此类字符,则返回-1。-1表示在给定的字符串中未找到字符
在其清晰的文字中:
如果此字符串中没有出现此类字符,则返回-1
-1表示在给定的字符串中未找到字符
在其清晰的文字中:
如果此字符串中没有出现此类字符,则返回-1
如果c
不会出现在remove
中,字符串返回-1
如果c
不会出现在remove
中,则字符串返回-1
indexOf()
返回匹配字符串的索引…如果未找到,则返回-1
e、 g
如果字符串是“hello”,那么“ello”的索引是1(因为它位于位置1)
或
如果字符串是“hello”,则“bla”的索引是-1(因为找不到它,所以索引返回-1)
引用位于indexOf()
返回匹配字符串的索引…如果未找到,则返回-1
e、 g
如果字符串是“hello”,那么“ello”的索引是1(因为它位于位置1)
或
如果字符串是“hello”,则“bla”的索引是-1(因为找不到它,所以索引返回-1)
如果参数字符不在remove
变量中,则引用位于-1由indexOf
方法返回。如果参数字符不在remove
变量中,则-1由indexOf
方法返回
StringBuilder strB = new StringBuilder(yourstring);
strB.deleteCharAt(yourstring.length() - 1);
System.out.print( strB.toString());
如果你想制作一个JButton,它会像Backspace一样工作
如果你想让一个JButton像Backspace一样工作,这里有一个检查&看看你是否能找到它…和/或逐步使用调试器,看看会发生什么。检查&看看你是否能找到它…和/或逐步使用调试器,看看会发生什么。
StringBuilder strB = new StringBuilder(yourstring);
strB.deleteCharAt(yourstring.length() - 1);
System.out.print( strB.toString());