一、math类
①math常用的方法
package com.bdqn.text;
public class MathTest {
public static void main(String[] args) {
/**
* Math.sqrt()//计算平方根
* Math.cbrt()//计算立方根
* Math.pow(a,b)//计算a的b次方
* Math.min(a,b)//计算a,b中的最小值
* Math.max(a,b)//计算a,b中的最大值
*
*/
System.out.println(Math.sqrt(4));
System.out.println(Math.cbrt(23));
System.out.println(Math.pow(1, 10));
System.out.println(Math.min(19,12));
System.out.println(Math.max(23,32));
/**
* abs求绝对值
*/
System.out.println(Math.abs(-10.23));//10.23
System.out.println(Math.abs(20));//20
/**
* ceil天花板的意思,返回大的值
*/
System.out.println(Math.ceil(10.23));//11.00
System.out.println(Math.ceil(-12.12));//-12
/**
* floor地板的意思,就是返回小的值
*/
System.out.println(Math.floor(20.3));//20
System.out.println(Math.floor(-23.32));//-24.0
/**
* random 取得一个大于或者等于0.0小于不等于1.0的随机数
*
*/
System.out.println(Math.random());//0.8
System.out.println(Math.random()*2+1);
/**
* rint 四舍五入,返回double值
* 注意0.5的时候会取偶数
*/
System.out.println(Math.rint(10.7));//11
System.out.println(Math.rint(10.5));//10
System.out.println(Math.rint(11.5));//12
/**
* round四舍五入,float时返回int值,double返回long
*/
System.out.println(Math.round(10.4));//10
System.out.println(Math.round(10.9));//11
}
}
二、String 类
string类的的基本特性:
string类是final类,也即意味着string类不能被继承,并且它的成员方法都默认为final方法。
string类是通过char数组来保存字符串的。
string对象一旦创建就是固定不变了,对string对象的任何改变都不影响到原对象,相关的任何change操作都会生成新的对象。无论是sub,concat还是replace操作都不是原有的字符串上进行的,而是重新生成了一个新的字符串对象。也就是说进行这些操作后,最原始的字符串并没改变。
发生的发生