ecilpse环境下一些常用的函数代码(math/string/time)

包括 math 取整数,乘方,开方,对数string字符串长度,截取字符,指出字符位置,大小写转换,替换time 待补充

package function;


public class JavaFunction {


public static void main(String[] args) {
// TODO Auto-generated method stub
//math
System.out.println(Math.floor(-1.8));//取整,返回小于目标函数的最大整数,如下将会返回
System.out.println(Math.ceil(-1.8));//取整,返回发育目标数的最小整数
System.out.println(Math.round(-1.8));//四舍五入取整数
System.out.println(Math.sqrt(9));//计算平方根
System.out.println(Math.cbrt(27));//计算立方根
System.out.println(Math.exp(2));//回欧拉数e的n次幂
System.out.println(Math.pow(2,3));//乘方(前底数,后指数)
System.out.println(Math.log(10));//自然对数(java只支持自然对数,需要使用换底公式logx(y) =loge(x) / loge(y))
System.out.println(Math.log(8)/Math.log(2));//以2为底8的对数
System.out.println(Math.abs(-10.8));//计算绝对值
System.out.println(Math.max(-10.8,8.8));//计算绝对值(只能支持两个数据比较)
System.out.println(Math.min(-10.8,8.8));//计算绝对值(只能支持两个数据比较)
System.out.println(Math.random());//返回一个伪随机数,该数大于等于0.0并且小于1.0
//math
//缺保留小数情况下的四舍五入
//string
String strE1 = new String(" you jump, I jump ");//声明变量 
String strE2 = new String("GREEN");//声明变量 
String strC1 = new String("可怜无定河边骨");//声明变量
String strC2 = new String("犹是深闺梦里人");//声明变量
System.out.println(strC2.length());//字符串长度,支持中文     返回结果 int
System.out.println(strC1.charAt(5));//英文字母下截取指定位置的一个字符,从0开始    返回结果 int
System.out.println(strC1.indexOf("河边",2));//从指定位置寻找指定字符.没有找到返加-1    返回结果 int
System.out.println(strE1.equalsIgnoreCase(strE2));//从指定位置寻找指定字符.没有找到返加-1    返回结果   boolean
System.out.println(strE1.toUpperCase());//字符串改大写   返回结果    String
System.out.println(strE1.toLowerCase());//字符串改大写   返回结果    String
System.out.println(strE1.trim());//删除字符串前的空格 返回结果    String
System.out.println(strE1.replace("ump",strE2));//从指定位置寻找指定字符.没有找到返加-1    返回结果  String
//string
   }
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值