public class Test { public static void main(String[] args) { String s=" classjava boy"; if(s.trim().lastIndexOf(" ")==-1) System.out.println("字符串中间没有空格"); else System.out.println("字符串中间有空格");
} }
public class Test { public static void main(String[] args) { String s=" classjava boy"; if(s.trim().lastIndexOf(" ")==-1) System.out.println("字符串中间没有空格"); else System.out.println("字符串中间有空格");
if(str.indexOf(" ")!=-1) System.out.print("There are spaces!"):
能不能详细一点啊?我是新手~~
可以把代码贴出来么?谢谢。
String flag="false";
for(int i=0;i<test_blank.length();i++){
if(test_blank.substring(i,i+1).equals(" ")){
flag="true";
}
}
if(flag=="true"){
out.println("有空格");
}
{
public static void main(String[] args)
{
String s=" classjava boy";
if(s.trim().lastIndexOf(" ")==-1)
System.out.println("字符串中间没有空格");
else
System.out.println("字符串中间有空格");
}
}
{
public static void main(String[] args)
{
String s=" classjava boy";
if(s.trim().lastIndexOf(" ")==-1)
System.out.println("字符串中间没有空格");
else
System.out.println("字符串中间有空格");
}
}正解!!!