當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


Java MathContext hashCode()用法及代碼示例

MathContext類hashCode()方法

  • hashCode() 方法可在java.math包。
  • hashCode() 方法用於獲取此 MathContext 的哈希碼值。
  • hashCode() 方法是一個非靜態方法,它隻能通過類對象訪問,如果我們嘗試使用類名訪問方法,那麽我們將得到一個錯誤。
  • hashCode() 方法在返回哈希碼時不拋出異常。

用法:

    public int hashCode();

參數:

  • None

返回值:

這個方法的返回類型是int,它檢索此 MathContext 哈希碼值。

例:

// Java program to demonstrate the example 
// of int hashCode() method of MathContext

import java.math.*;

public class HashCodeOfMC {
    public static void main(String args[]) {
        // Initialize three MathContext objects  
        MathContext ma_co1 = new MathContext(3, RoundingMode.CEILING);
        MathContext ma_co2 = new MathContext(4);
        MathContext ma_co3 = new MathContext(6, RoundingMode.FLOOR);

        // returns the hash code of this MathContext
        // ma_co1 
        int hash_code = ma_co1.hashCode();
        System.out.println("ma_co1.hashCode():" + hash_code);

        // returns the hash code of this MathContext
        // ma_co2 
        hash_code = ma_co2.hashCode();
        System.out.println("ma_co2.hashCode():" + hash_code);

        // returns the hash code of this MathContext
        // ma_co3 
        hash_code = ma_co3.hashCode();
        System.out.println("ma_co3.hashCode():" + hash_code);
    }
}

輸出

ma_co1.hashCode():1420167577
ma_co2.hashCode():931231881
ma_co3.hashCode():-18805464


相關用法


注:本文由純淨天空篩選整理自Preeti Jain大神的英文原創作品 Java MathContext Class | hashCode() Method with Example。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。