java 根据类名示例化类_Java MathContext类| 带示例的getRoundingMode()方法

java 根据类名示例化类

MathContext类的getRoundingMode()方法 (MathContext Class getRoundingMode() method)

  • getRoundingMode() method is available in java.math package.

    getRoundingMode()方法在java.math包中可用。

  • getRoundingMode() method is used to get the RoundingMode value of this MathContext if defined and there are many constants of Rounding Mode like DOWN, CEILING, UNNECESSARY, FLOOR, etc.

    如果已定义,则getRoundingMode()方法用于获取此MathContext的RoundingMode值,并且舍入模式有许多常量,如DOWN,CEILING,UNNECESSARY,FLOOR等。

  • getRoundingMode() method is a non-static method, it is accessible with the class object only and if we try to access the method with the class name then we will get an error.

    getRoundingMode()方法是一种非静态方法,仅可通过类对象访问,如果尝试使用类名访问该方法,则会收到错误消息。

  • getRoundingMode() method does not throw an exception at the time of getting round mode.

    在获取回合模式时, getRoundingMode()方法不会引发异常。

Syntax:

句法:

    public RoundingMode getRoundingMode();

Parameter(s):

参数:

  • None

    没有

Return value:

返回值:

The return type of this method is RoundingMode, it returns the RoundingMode constants whatever be defined with this MathContext.

此方法的返回类型为RoundingMode ,无论此MathContext定义什么,它都会返回RoundingMode常量。

Example:

例:

// Java program to demonstrate the example 
// of RoundingMode getRoundingMode() method of MathContext

import java.math.*;

public class GetRoundingModeOfMC {
    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 rounding mode of this MathContext
        // ma_co1 i.e. RoundingMode is the second
        // parameter set in MathContext Constructor
        // i.e. CEILING in ma_co1
        RoundingMode rm = ma_co1.getRoundingMode();
        System.out.println("ma_co1.getRoundingMode(): " + rm);

        // returns the rounding mode of this MathContext
        // ma_co2 i.e. RoundingMode is the second
        // parameter set in MathContext Constructor
        // i.e. HALF_UP in ma_co2 it the default set
        // when we don't use other rounding mode
        rm = ma_co2.getRoundingMode();
        System.out.println("ma_co2.getRoundingMode(): " + rm);

        // returns the rounding mode of this MathContext
        // ma_co3 i.e. RoundingMode is the second
        // parameter set in MathContext Constructor
        // i.e. FLOOR in ma_co1
        rm = ma_co3.getRoundingMode();
        System.out.println("ma_co3.getRoundingMode(): " + rm);
    }
}

Output

输出量

ma_co1.getRoundingMode(): CEILING
ma_co2.getRoundingMode(): HALF_UP
ma_co3.getRoundingMode(): FLOOR


翻译自: https://www.includehelp.com/java/mathcontext-getroundingmode-method-with-example.aspx

java 根据类名示例化类

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值