Convert Long to numeric primitive data types example

   1.
      /*
   2.
        Convert Long to numeric primitive data types example
   3.
        This example shows how a Long object can be converted into below given numeric
   4.
        data types
   5.
        - Convert Long to byte
   6.
        - Convert Long to short
   7.
        - Convert Long to int
   8.
        - Convert Long to float
   9.
        - Convert Long to double
  10.
      */
  11.
       
  12.
      public class LongToNumericPrimitiveTypesExample {
  13.
       
  14.
        public static void main(String[] args) {
  15.
          Long lObj = new Long("10");
  16.
          //use byteValue method of Long class to convert it into byte type.
  17.
          byte b = lObj.byteValue();
  18.
          System.out.println(b);
  19.
         
  20.
          //use shortValue method of Long class to convert it into short type.
  21.
          short s = lObj.shortValue();
  22.
          System.out.println(s);
  23.
         
  24.
          //use intValue method of Long class to convert it into int type.
  25.
          int i = lObj.intValue();
  26.
          System.out.println(i);
  27.
         
  28.
          //use floatValue method of Long class to convert it into float type.
  29.
          float f = lObj.floatValue();
  30.
          System.out.println(f);
  31.
       
  32.
          //use doubleValue method of Long class to convert it longo double type.
  33.
          double d = lObj.doubleValue();
  34.
          System.out.println(d);
  35.
        }
  36.
      }
  37.
       
  38.
      /*
  39.
      Output of the program would be :
  40.
      10
  41.
      10
  42.
      10
  43.
      10.0
  44.
      10.0
  45.
      */


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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值