Java完善程序题2

来源:百度知道 编辑:UC知道 时间:2024/06/06 09:29:22
class IenString
{ public static void main(String args[])
{ int index=-1,length=0,n=0;
String str="我非常喜欢1236" ;
index=【代码1】 //str调用方法返回"1236"在str出现的位置
length=【代码2】 //str调用方法返回str中字符的个数
char c=【代码3】 //str调用方法返回str中的字符:'喜'
String temp=【代码4】 //str调用方法返回字符串"1236"
n=【代码5】 //将temp转化为int型数据。
System.out.println(n);
}
}

public static void main(String[] args) {
int index=-1,length=0;
String temp;
String str="我非常喜欢1236" ;
index=str.indexOf("1236"); //str调用方法返回"1236"在str出现的位置
length=str.length(); //str调用方法返回str中字符的个数
char c=str.charAt(3); //str调用方法返回str中的字符:'喜'
temp=str.substring(5);//str调用方法返回字符串"1236"
int n=Integer.parseInt(temp); //将temp转化为int型数据。
System.out.println(c);
System.out.println(temp);
//System.out.println(n);
}

index=s.indexOf("1236");//str调用方法返回"1236"在str出现的位置
length=str.length(); //str调用方法返回str中字符的个数
char c=str.charAt(1) //str调用方法返回str中的字符:'喜' . charAt(int index)方法索引值处的字符。
String temp=sre.substring(0); //str调用方法返回字符串"1236"
n=str.parseInt(temp); //将temp转化为int型数据。