public class Test1 {
public static void main(String[] args) {
String s="this is a test of java";
char [] c=s.toCharArray();
count(c); //统计s的个数;
getTest(s); //取出test;
char[]str=s.toCharArray(); //复制到字符串数组中
toBig(str); //单词的首字母变成大写
method1(s);
System.out.println();
mothod2(s);
String[]str1=s.split(" ");
method3(str1);
}
public static void method3(String[] str1) {
for (String string : str1) {
System.out.print(string+" ");
}
}
public static void method1(String s) {
char[]str=s.toCharArray();
for (int i = str.length-1; i >=0; i--) {
System.out.print(str[i]);
}
}
public static void toBig(char[] str) {
int tobig='A'-'a';
str[0]=(char)(str[0]+tobig);
for (int i = 1; i < str.length; i++) {
if (str[i]==' ') {
str[i+1]+=tobig;
}
}
String strNew=String.valueOf(str);
System.out.println(strNew);
}
public static void getTest(String s) { //取出字符串"test"
String [] str=s.split(" ");
for (int i = 0; i < str.length; i++) {
if (str[i].equals("test")) {
System.out.println(str[i]);
break;
}
}
}
public static void count(char[] c) {
int count=0;
for (int i = 0; i < c.length; i++) {
if (c[i]=='s') {
count++;
}
}
System.out.println("count="+count);
}
} 作者: 老司机带带我 时间: 2016-11-19 13:12