zoukankan      html  css  js  c++  java
  • [Java] 常用类-02 基础数据类型包装类 / Math 类

    public class TestParser {
        public static void main(String[] args) {
            Integer i = new Integer(100);
            Double d = new Double("123.456");
            int j = i.intValue() + d.intValue();
            float f = i.floatValue() + d.floatValue();
            System.out.println(j);
            System.out.println(f);
            double pi = Double.parseDouble("3.1415926");
            double r = Double.valueOf("2.0").doubleValue();
            double s = pi * r * r;
            System.out.println(s);
            try {
                int k = Integer.parseInt("1.25");
            } catch (NumberFormatException e) {
                System.out.println("数据格式不对");
            }
            System.out.println(Integer.toBinaryString(123) + "B");
            System.out.println(Integer.toHexString(123) + "H");
            System.out.println(Integer.toOctalString(123) + "O");
        }
    }
    
    1111011B
    7bH

    173 O

    public class ArrayParser {
        public static void main(String[] args) {
            double[][] d;
            String s = "1,2;3,4,5;6,7,8";
            String[] sFirst = s.split(";");
            d = new double[sFirst.length][];
            for (int i = 0; i < sFirst.length; i++) {
                String[] sSecond = sFirst[i].split(",");
                d[i] = new double[sSecond.length];
                for (int j = 0; j <sSecond.length; j++) {
                    d[i][j] = Double.parseDouble(sSecond[j]);
                }
            }
            
            for (int i = 0; i <d.length; i++) {
                for (int j = 0; j < d[i].length; j++) {
                    System.out.print(d[i][j] + " ");
                }
                System.out.println();
            }
        }
    }
    
    1.0 2.0 
    3.0 4.0 5.0 
    6.0 7.0 8.0 
    public class TestMath {
        public static void main(String[] args) {
            double a = Math.random();
            double b = Math.random();
            System.out.println(Math.sqrt(a*a + b*b));
            System.out.println(Math.pow(a, 8));
            System.out.println(Math.round(b)); // re long
            System.out.println(Math.log(Math.pow(Math.E, 15)));
            double d = 60.0, r = Math.PI / 4;
            System.out.println(Math.toRadians(d));
            System.out.println(Math.toDegrees(r));  
        }
    }
    
    1.0152118816776885
    0.004305269426978659
    1
    15.0
    1.0471975511965976
    45.0

  • 相关阅读:
    github入门到上传本地项目
    17-索引
    16-pymysql模块的使用
    15-可视化工具Navicat的使用
    C语言/C++知识
    Apk反编译那些事
    CTF基本常识
    WebView net::ERR_CLEARTEXT_NOT_PERMITTED&&net::ERR_INTERNET_DISCONNECTED
    测试
    zookeeper-3.4.5安装&3台机器安装之后 ./zkServer.sh status 之后会显示“Error contacting service. It is probably not running.”的解决办法
  • 原文地址:https://www.cnblogs.com/robbychan/p/3786909.html
Copyright © 2011-2022 走看看