java判断是否小数

内容摘要
java判断是否是小数:public class JudgeNumber {

public static boolean judgeIsDecimal(String num){

boolean isdecimal = false;

文章正文

java判断是否是小数:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
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()方法

1
public boolean contains(CharSequence s)

参数:

s-- This is the sequence to search for.

返回值:

如果此字符串包含,此方法返回true,否则返回false。

更多java知识请关注java基础教程。

代码注释
[!--zhushi--]

作者:喵哥笔记

IDC笔记

学的不仅是技术,更是梦想!