欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

java基础--常用函数总结

程序员文章站 2023-10-31 19:12:28
java基础--常用函数总结 2019-3-16-23:28:01 云林原创 1、split()字符串分割函数 将一个字符串分割为子字符串,然后将结果作为字符串数组返回。 2、Math.floor( )舍掉小数取整数 3、Math.rint( )四舍五入取整数 4、Math.ceil( )进位取整数 ......

java基础--常用函数总结

 

 


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]);
            }


}

 

}