java判断是否是小数:
public class JudgeNumber { public static boolean judgeIsDecimal(String num){ boolean isdecimal = false; if (num.contains(".")) { isdecimal=true; } return isdecimal; } public static void main(String[] args) { //测试的main方法 int num1 = 34; double num2=67.8; boolean is1 = judgeIsDecimal(String.valueOf(num1)); boolean is2=judgeIsDecimal(String.valueOf(num2)); System.out.println(is1);//fasle System.out.println(is2);//true } }
Java String.contains()方法,当且仅当此字符串包含指定的char值序列时,返回true。
以下是声明java.lang.String.contains()方法
public boolean contains(CharSequence s)
参数:
s– This is the sequence to search for.
返回值:
如果此字符串包含,此方法返回true,否则返回false。