String toString();
将底层的char类型数组保存的字符内容转换成对应的String类型字符串返回
int length();
返回底层char类型数组中有多少有效元素。
String substring(int begin);
从指定位置开始获取到char类型数组有效元素末尾对应的字符串,截取操作,
String substring(int begin, int end);
从指定位置begin开始到end结束,获取对应的字符串,要头不要尾
int indexOf(String str);
指定元素字符串所在下标位置
int lastIndexOf(String str);
指定元素字符串最后一次所在下标位置
1.5 修改方法
replace(int start, int end, String str);
从指定位置start开始,到end结束,start <= n < end, 使用str替换
setCharAt(int index, char ch);
使用ch替换指定下标index对应的字符
1.6 删除和反序
delete(int start, int end);
删除指定范围以内的字符 start <= n < end
deleteCharAt(int index);
删除指定下标的字符
reverse();
逆序
2. Math数学类
Java中一些数学方法
public static double abs(double a);
返回值为绝对值
public static double ceil(double a);
向上取整
public static double floor(double a);
向下取整
public static double round(double a);
四舍五入
public static double random();
随机数 0.0 <= n < 1.0
2.1 抽奖小演示
package com.qfedu.b_math;publicclassDemo2{publicstaticvoidmain(String[] args){for(int i =0; i <20; i++){double num = Math.random()*100;if(0.0<= num && num <50){
System.out.println("绿色普通卡");}elseif(50<= num && num <80){
System.out.println("蓝色高端卡");}elseif(80<= num && num <98){
System.out.println("紫色传说卡");}else{
System.err.println("黄金史诗卡");}}}}