可以使用String類的contains()方法來判斷字符串是否包含小數點。具體代碼如下:
public class Main {
public static void main(String[] args) {
String str1 = "123.45";
String str2 = "abc";
boolean hasDecimalPoint1 = str1.contains(".");
boolean hasDecimalPoint2 = str2.contains(".");
System.out.println("str1 contains decimal point: " + hasDecimalPoint1);
System.out.println("str2 contains decimal point: " + hasDecimalPoint2);
}
}
輸出結果為:
str1 contains decimal point: true
str2 contains decimal point: false
上述代碼中,使用contains()方法來判斷字符串是否包含小數點,如果包含小數點,返回true;否則,返回false。