double.isnan_Java Double类isNaN()方法与示例

double.isnan

Syntax:

句法:

    public boolean isNaN ();
    public static boolean isNaN(double value);

双类isNaN()方法 (Double class isNaN() method)

  • isNaN() method is available in java.lang package.

    isNaN()方法在java.lang包中可用。

  • isNaN() method is used to check NaN (Not a Number) values (i.e. either positive NaN or negative NaN).

    isNaN()方法用于检查NaN(非数字)值(即正NaN或负NaN)。

  • isNaN(double value) method is used to check NaN values for the given double argument (i.e. either positive or negative NaN).

    isNaN(double value)方法用于检查给定双精度参数的NaN值(即正或负NaN)。

  • isNaN() method does not throw an exception at the time of checking NaN values represented by the object.

    在检查对象表示的NaN值时, isNaN()方法不会引发异常。

  • Similarly, isNaN(double value) method does not throw an exception at the time of checking NaN values of the given argument.

    同样, isNaN(double value)方法在检查给定参数的NaN值时也不会引发异常。

  • Both types of methods are the non-static methods, they are accessible with the class object only and if we try to access them with the class name then we will get an error.

    两种类型的方法都是非静态方法,它们只能通过类对象访问,如果尝试使用类名称访问它们,则会收到错误消息。

Parameter(s):

参数:

  • In the first case isNaN(), we don't pass any parameter or value.

    在第一种情况下, isNaN() ,我们不传递任何参数或值。

  • In the second case isNaN(double value), we pass only one parameter of double type, it represents the double value to be tested for NaN.

    在第二种情况下是NaN (double value) ,我们仅传递一个double类型的参数,它表示要测试NaN的double值。

Return value:

返回值:

The return type of this method is boolean, it returns wither "true" if the value if either positive or negative NaN, it returns "false" if the value is not NaN.

此方法的返回类型是布尔值 ,则返回枯萎“真”如果要是正或负的NaN,如果它的值不为NaN返回“假”的值。

Example:

例:

// Java program to demonstrate the example 
// of isNaN() method of Double class

public class IsNaNOfDoubleClass {
    public static void main(String[] args) {
        // Object initialization
        Double ob1 = new Double(0.0 / 0.0);
        Double ob2 = new Double(-0.0 / 0.0);
        Double ob3 = new Double(20.0);

        // Display ob1,ob2 and ob3 values
        System.out.println("ob1: " + ob1);
        System.out.println("ob2: " + ob2);
        System.out.println("ob3: " + ob3);

        // It checks NaN by calling ob1.isNaN() for ob1
        // and ob2.isNaN() for ob2  
        boolean NaN1 = ob1.isNaN();
        boolean NaN2 = ob2.isNaN();

        // It also checks NaN of this Double object by calling
        // ob3.isNaN(ob3) for ob3 
        boolean NOTNaN = ob3.isNaN(ob3);

        // Display result values
        System.out.println("ob1.isNaN(): " + NaN1);
        System.out.println("ob2.isNaN(): " + NaN2);
        System.out.println("ob3.isNaN(ob3): " + NOTNaN);
    }
}

Output

输出量

ob1: NaN
ob2: NaN
ob3: 20.0
ob1.isNaN(): true
ob2.isNaN(): true
ob3.isNaN(ob3): false


翻译自: https://www.includehelp.com/java/double-class-isnan-method-with-example.aspx

double.isnan

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
将以下java代码转换成matlab:def calculate_size_ratio(target_diameter, neighbor_trees): """ 计算大小比数(Size Ratio)。 参数: - target_diameter:参照树的胸径 - neighbor_trees:邻近树列表,包含四棵邻近树的胸径 返回值: - 大小比数(Size Ratio):介于0和1之间的值,表示参照树与邻近树之间的胸径大小比例 """ size_sum = 0 for neighbor in neighbor_trees: if pd.notnull(neighbor) and pd.to_numeric(neighbor, errors="coerce") < target_diameter: # 如果邻近树的胸径有效且小于参照树的胸径 size_sum += 1 # 大小比数加1 size_ratio = size_sum / len(neighbor_trees) # 计算大小比数 return size_ratio def main(): """ 主函数,用于执行计算混交度和大小比数的示例。 """ target_species = input("请输入目标树的树种:") # 输入目标树的树种 # 从Excel中读取邻近树数据 neighbor_data = pd.read_excel(r"C:\Users\23714\Desktop\样地数据.xls") # 替换为您的邻近树数据Excel文件路径 neighbor_trees = neighbor_data["树种"].tolist() # 从Excel中读取参照树数据 reference_data = pd.read_excel(r"C:\Users\23714\Desktop\样地数据.xls") # 替换为您的参照树数据Excel文件路径 target_diameter = reference_data.loc[reference_data["树种"] == target_species, "胸径"].values target_diameter = pd.to_numeric(target_diameter, errors="coerce")[0] # 转换为数值型,只获取第一个有效值 mixing_degree = calculate_mixing_degree(target_species, neighbor_trees) # 计算混交度 size_ratio = calculate_size_ratio(target_diameter, neighbor_trees) # 计算大小比数 print("混交度 (Mixing Degree):", mixing_degree) print("大小比数 (Size Ratio):", size_ratio) if name == 'main': main()
06-06
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值