package shyzye;
public class shsan {
public static void main(String[] args) {
// TODO Auto-generated method stub
String str="this is a test of java";
int count=0;
char[] c=str.toCharArray();
for(int i=0;i<c.length;i++) {
if(c[i]=='s') {
count++;
}
}
System.out.println("S的个数:"+count);
}
}
package shyzye;
public class shsan2 {
public static void main(String[] args) {
// TODO Auto-generated method stub
String str="this is a test of java";
int count=0;
String[] c=str.split(" ");
for(String e:c) {
if(e.equals("is")) {
count++;
}
}
System.out.println("is作为单词出现的次数:"+count);
}
}
package shyzye;
public class shsan3 {
public static void main(String[] args) {
String str="this is a test of java";
int i=0;
int count=0;
while(str.indexOf("is",i)!=-1){
count++;
i=str.indexOf("is",i)+1;
}
System.out.println("is作为字符出现的次数:"+count);
}
}
package shyzye;
public class shsan4 {
public static void main(String[] args) {
// TODO Auto-generated method stub
StringBuffer str=new StringBuffer();
str.append("this is a test of java");
System.out.print("倒序:"+str.reverse());
}
}
package shyzye;
import java.util.*;
public class shsan二 {
public static void main(String[] args) {
int i,j=0;
Scanner scanf=new Scanner(System.in);
String str=scanf.nextLine();
char chr[]=str.toCharArray();
char[] chr1=null;
chr1 = new char[str.length()];
for(i=chr.length-3;i<chr.length;i++) {
chr1[j]=chr[i];
j++;
}
for(i=0;i<chr.length-3;i++){
chr1[j]=chr[i];
j++;
}
System.out.print(chr1);
}
}
package shyzye;
public class shsans {
public static void main(String[] args) {
// TODO Auto-generated method stub
String str1="ddejidsEFALDFfnef2357 3ed";
int count1=0,count2=0,count3=0;
char[] up=str1.toCharArray();
for(int i=0;i<up.length;i++) {
if(up[i]>='a'&&up[i]<='z') {
count1++;
}
else if(up[i]>='A'&&up[i]<='Z') {
count2++;
}
else {
count3++;
}
}
System.out.println("小写英文字母:"+count1);
System.out.println("大写英文字母:"+count2);
System.out.println("其他字符:"+count3);
}
}
原文:https://www.cnblogs.com/lyl68/p/11595066.html