2019-3-16-23:28:01----- 云林原创
1,split() 字符串分割函数
将一个字符串分割为子字符串, 然后将结果作为字符串数组返回.
2,Math.floor( ) 舍掉小数取整数
3,Math.rint( ) 四舍五入取整数
4,Math.ceil( ) 进位取整数
5,IndexOf( ) 查找特定字符出现的索引
-----------------------------------------> 特定字符出现的最先出现的位置: IndexOf();
-----------------------------------------> 特定字符出现的最后出现的位置: lastIndexOf();
-----------------------------------------> 特定字符不存在时返回 - 1;
6, 大小写转换
-----------------------------------------> 转换为大写: toUpperCase();
-----------------------------------------> 转换为大写: toLowerCase();
7,Math.random() 取随机数
-----------------------------------------> 令系统随机选取大于等于 0.0 且小于 1.0 的伪随机 double 值
8,Math.abs() 绝对值
9, 计算乘方数 (3 的 4 方)
10, 最值 (max,min)
- -------->Math.min( , );
- -------->Math.max( , );
用法实例:
- public class test{
- public static void main(String[] args) {
- // TODO Auto-generated method stub
- // 计算乘方数 (3 的 2 次方)
- System.out.print("计算乘方数 :");
- System.out.println(Math.pow(3, 2));
- // 绝对值
- System.out.print("绝对值:");
- System.out.println(Math.abs(-9));
- // 最小值
- System.out.print("最小值:");
- System.out.println(Math.min(6, 9));
- // 最大值
- System.out.print("最大值:");
- System.out.println(Math.max(6, 9));
- // 取随机数
- System.out.print("取随机数:");
- for(int i=0;i<10;i++)
- {
- int num=(int) (Math.random()*100);
- System.out.print(num+" ");
- }
- // 大小写转换
- System.out.println();
- System.out.println("大小写转换:");
- String str="boss is yunlin";
- System.out.println("转换为大写:"+str.toUpperCase());
- System.out.println("转换为小写:"+str.toLowerCase());
- // 特定字符出现的索引
- System.out.println("i 最后出现的位置:"+str.IndexOf("i"));
- System.out.println("i 最后出现的位置:"+str.lastIndexOf("i"));
- System.out.println("a 不存在是返回 - 1:"+str.lastIndexOf("a"));
- // 进位取整数
- System.out.println("进位取整"+Math.ceil(3.56));
- // 四舍五入取整数
- System.out.println("四舍五入取整数:"+Math.rint(3.2));
- // 舍掉小数取整数
- System.out.println("去掉小数取整数:"+Math.floor(3.6));
- // 字符串分割函数
- System.out.println("字符串分割函数");
- String str1="boss is yunlin";
- String[] array= str1.split(" ");
- for(int i=0;i<array.length;i++) {
- System.out.println(i+"<----->"+array[i]);
- }
- }
- }
来源: http://www.bubuko.com/infodetail-2990002.html