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^!

  • 相关阅读:
    jQuery(四)
    jQuery(三)
    jQuery(二)
    jQuery(一)
    JS(四)
    JS(三)
    JS(二)
    类似openDialog的弹窗
    vue的异步组件按需加载
    vue实现点击、滑动右侧字母对应各个城市
  • 原文地址:https://www.cnblogs.com/yocichen/p/8543668.html
Copyright © 2011-2022 走看看