标签:
//1、查找“asdfjvjadsffvaadfkfasaffdsasdffadsafafsafdadsfaafd”
//该字符串中有多少个af
public static void main(String[] args) {
String st = "asdfjvjadsffvaadfkfasaffdsasdffadsafafsafdadsfaafd";
int x = 0;
char[] charArray = st.toCharArray();
for (int i = 0; i < st.length() - 1; i++) {
if (charArray[i] == ‘a‘ && charArray[i + 1] == ‘f‘) {
x++;
}
}
System.out.println(x);
}
/*输入任意一个字符串,如:“abDEe23dJfd343dPOddfe4CdD5ccv!23rr”。 取出该字符串中所有的字母组成新的字符串。顺序不能改变!并把大写字 母变成小写,小写字母变成大写!*/
public static void main(String[] args) {
String st="abDEe23dJfd343dPOddfe4CdD5ccv!23rr";
char[] array = st.toCharArray();
for(int i = 0;i<array.length;i++){
if(array[i] >= ‘a‘&& array[i]<=‘z‘){
array[i] -= 32;
System.out.print(array[i]);
}else if(array[i] >= ‘A‘&& array[i]<=‘Z‘){
array[i] +=32;
System.out.print(array[i]);
}
}
}
标签:
原文地址:http://www.cnblogs.com/zzj951103/p/5547288.html