zoukankan      html  css  js  c++  java
  • java基础(一)---数据类型&Math方法&强制转换

    数据类型及各种Math类方法


     1 public class HelloWorld {
     2     public static void main(String args[]) {
     3         //各种数据类型的熟悉掌握,强制类型转换要看级别
     4         final int var = 100;
     5         int varr = 200;
     6         float m = -21.5f;
     7         double p = 21.234;
     8         boolean judge = true;
     9         char ch = 'a';
    10         long num = 625;
    11         short num1 = 12;
    12         byte a = 1;
    13         String str = "I am a great boy!";
    14         
    15         //算术运算依赖Math类各种静态方法
    16         System.out.println(Math.abs(m));    //绝对值
    17         System.out.println(Math.sin(a));        //三角函数
    18         System.out.println(Math.asin(0.5));//反三角函数
    19         System.out.println(Math.sqrt(var));//开平方跟
    20         System.out.println(Math.cbrt(num));//开立方根
    21         System.out.println(Math.round(m));//四舍五入
    22         System.out.println(Math.ceil(1.5));//向上取整
    23         System.out.println(Math.floor(1.9));//向下取整
    24         System.out.println(Math.max(100, 50));//取大值
    25         System.out.println(Math.min(12.3, 13.3));//取小值
    26         System.out.println(Math.random()+1);//生成随机数
    27         System.out.println(Math.pow(2, 10));//指数运算:计算        
    28 a(前者)的b(后者)次幂
    29         System.out.println(Math.log10(100));//对数运算
    30     }
    31 }        
    //以上代码eclipse编译通过


     

    强制类型转换



    欢迎留言讨论 ^w^!

  • 相关阅读:
    Webpack打包原理
    Vue——VNode
    Vue——响应式原理
    HTTP2.0——头部压缩
    HTTP2.0
    浏览器打开2个页面会有几个进程?
    计算机网络——TCP如何保证可靠性
    操作系统——进程之间的通信
    前端路由hash与history下
    前端路由hash与history上
  • 原文地址:https://www.cnblogs.com/yocichen/p/8543668.html
Copyright © 2011-2022 走看看