【java基础】第17天——包装类、System类、Math类、Arrays

今日内容介绍
1、基本类型包装类
2、System类
3、Math类
4、Arrays类
5、大数据运算

=======================第一节课开始=============================================

A:Integer类其他方法
/

* Integer类的3个静态方法
* 做进制的转换
* 十进制转成二进制 toBinarString(int)
* 十进制转成八进制 toOctalString(int)
* 十进制转成十六进制 toHexString(int)
* 三个方法,返回值都是以String形式出现
/
a:十进制转二,八,十六进制
public static void function_1(){
System.out.println(Integer.toBinaryString(99));
System.out.println(Integer.toOctalString(99));
System.out.println(Integer.toHexString(999));
}
b:获取int的最大值和最小值
/

* Integer类的静态成员变量
* MAX_VALUE
* MIN_VALUE
*/
public static void function(){
System.out.println(Integer.MAX_VALUE);
System.out.println(Integer.MIN_VALUE);
}

*A:自动装箱与自动拆箱:
//JDK1.5新特性
//自动装箱,拆箱的 好处: 基本类型和引用类直接运算
//自动装箱:使用Integer.valueOf(整数值)返回一个封装了该整数值的Integer对象
//自动拆箱:使用Integer对象.intValue()返回Integer对象中封装的整数值
public static void function(){
//引用类型 , 引用变量一定指向对象
//自动装箱, 基本数据类型1, 直接变成了对象

*A:自动装箱与自动拆箱:
Integer i = new Integer(1);
Integer j = new Integer(1);
System.out.println(i==j);// false 对象地址
System.out.println(i.equals(j));// true 继承Object重写equals,比较的对象数据

=========================第二节课开始====================================

A:System类方法currentTimeMillis():用于计算程序的执行时间
/

* 获取系统当前毫秒值
* static long currentTimeMillis()
* 对程序执行时间测试
*/
public static void function(){
long start = System.currentTimeMillis();//当前时间x-1970年1月1日零时零分零秒
for(int i = 0 ; i < 10000; i++){
System.out.println(i);
}
long end = System.currentTimeMillis();//当前时间y-1970年1月1日零时零分零秒
System.out.println(end – start);//当前时间y-当前时间x
}

A:System类方法gc
public class Person {
public void finalize(){
System.out.println(“垃圾收取了”);
}
}

A:System类方法getProperties(了解)
/
* 获取当前操作系统的属性:例如操作系统名称,
* static Properties getProperties()
/
public static void function_3(){
System.out.println( System.getProperties() );
}

================================第三节课开始======================================================

A:Math类中的方法
/
* static double sqrt(double d)
* 返回参数的平方根
/
public static void function_4(){
double d = Math.sqrt(-2);
System.out.println(d);
}

A:Math类的方法_2
/
* static double round(doubl d)
* 获取参数的四舍五入,取整数
/
public static void function_6(){
double d = Math.round(5.4195);
System.out.println(d);
}

/
* static double random() 返回随机数 0.0-1.0之间
* 来源,也是Random类
/
public static void function_5(){
for(int i = 0 ; i < 10 ;i++){
double d = Math.random();
System.out.println(d);
}
}

====================第四节课开始============================

A:BigDecimal类概述

A:BigDecimal类实现加法减法乘法
/
* BigDecimal实现三则运算
* + – *
/
public static void function(){
BigDecimal b1 = new BigDecimal(“0.09”);
BigDecimal b2 = new BigDecimal(“0.01”);
//计算b1+b2的和,调用方法add
BigDecimal bigAdd = b1.add(b2);
System.out.println(bigAdd);

Original: https://blog.51cto.com/u_11037231/5591550
Author: 一片白纸
Title: 【java基础】第17天——包装类、System类、Math类、Arrays

原创文章受到原创版权保护。转载请注明出处:https://www.johngo689.com/508285/

转载文章受原作者版权保护。转载请注明原作者出处!

(0)

大家都在看

亲爱的 Coder【最近整理,可免费获取】👉 最新必读书单  | 👏 面试题下载  | 🌎 免费的AI知识星球