Java中的整型和浮点字面量有什么区别?


整型字面量表示固定的整数,如 900、12、400、-222 等(在整数范围内)。

而浮点字面量表示小数,即具有小数值的数字,如 25.53、45.66、58.66 等。在编写这些字面量时,我们应该使用 f 或 F 表示法,如 25.53。

示例

实时演示

public class StringExample {
   public static void main(String args[]){
      int num1 = 100;
      float num2 = 30.0f;
      System.out.println("Value of integer:"+num1);
      System.out.println("Value of integer:"+num2);
   }
}

输出

Value of integer:100
Value of integer:30.0

更新于:2019-07-30

730 次浏览

开启您的职业生涯

通过完成课程获得认证

开始
广告
© . All rights reserved.