public class Hello { public static void main(String[] args) { String a = "111.23"; int index = a.indexOf("."); if (index < a.length() && index > 0) { System.out.println("有"); } else { System.out.println("没有"); } } }
public class Test{ public static void main(String[] args) { String a = "111.23"; int index = a.indexOf("."); if (index > a.length() || index < 0) { System.out.println("没有哦"); } else { System.out.println("有的"); } } } 这样就可以,也可以 试试看吧 多查api chm 或百度 都行啊 希望对你有帮助 ^_@
public class testString {
public static void main(String []args) throws ParseException{
String a = "11.21";
System.out.println(a.indexOf("."));
}
}
for(i=0;i<str.length;i ){ if(str.charAt(i)=='.'){
//就有'.'
}
}
2、正则表达式String s="111.23";
String parren = "^[1-9]+\\.{1}[0-9]+$";
Pattern p = Pattern.compile(parren);
Matcher m = p.matcher(s);
if(m.matches()){
System.out.println("带点");
}else{
System.out.println("不带点");
}
str.indexof(".");
这样返回的就是3即“.”在字符串中的位置,如要是没有的话就返回-1;
public class Hello { public static void main(String[] args) {
String a = "111.23";
int index = a.indexOf(".");
if (index < a.length() && index > 0) {
System.out.println("有");
} else {
System.out.println("没有");
}
}
}
public class Test{ public static void main(String[] args) {
String a = "111.23";
int index = a.indexOf(".");
if (index > a.length() || index < 0) {
System.out.println("没有哦");
} else {
System.out.println("有的");
}
}
}
这样就可以,也可以
试试看吧
多查api chm 或百度 都行啊
希望对你有帮助
^_@
indexOf(String str)
返回第一次出现的指定子字符串在此字符串中的索引;
lastIndexOf(String str)
返回在此字符串中最右边出现的指定子字符串的索引。
String str = "111.23";
char [] arr = str.toCharArray();
for(int i = 0;i < str.length();i++){
if(arr[i] == '.'){
System.out.println("有");
break;
}
}