标签:count ted gen image 输出 scan void 文字 info
① 统计该字符串中字母s出现的次数。
② 统计该字符串中子串“is”出现的次数。
③ 统计该字符串中单词“is”出现的次数。
④ 实现该字符串的倒序输出。
package test3;
public class Zifu {
public static void main(String[] args) {
// TODO Auto-generated method stub
String str = "this is a test of java";
char c[]=str.toCharArray();
char s='s';
int count=0;
for(int j=0;j<=c.length-1;j++)
if(s==c[j])
count++;
System.out.print("字符s出现的次数:"+count);
}
}
package test3;
public class Zifu {
public static void main(String[] args) {
// TODO Auto-generated method stub
String str = "this is a test of java";
char c[]=str.toCharArray();
char s='s',i='i';
int count=0;
for(int j=0;j<=c.length-1;j++)
if(i==c[j]&&s==c[j+1])
count++;
System.out.print(“字串is出现的次数:"+count);
}
}
package test3;
public class Zifu {
public static void main(String[] args) {
// TODO Auto-generated method stub
String str = "this is a test of java";
char c[]=str.toCharArray();
char s='s',i='i';
int count=0;
for(int j=0;j<=c.length-1;j++)
if(c[j]==' '&&i==c[j+1]&&s==c[j+2]&&c[j+3]==' ')
count++;
System.out.print("单词is出现的次数:"+count);
}
}
package test3;
public class Zifu {
public static void main(String[] args) {
// TODO Auto-generated method stub
String str = "this is a test of java";
String c[]=str.split(" ");
for(int j=c.length-1;j>=0;j--)
System.out.print(c[j]+" ");
}
}
package test4;
import java.util.Scanner;
public class Jiemi {
public static void main(String[] args) {
// TODO Auto-generated method stub
char a,b,d;
Scanner scanner = new Scanner(System.in);
String str=scanner.next();
char e[]=str.toCharArray();
char c[]=str.toCharArray();
String result[]=str.split("");
for(int x=0;x<result.length;x++) {
System.out.print(result[x]+" ");
}
System.out.println(" ");
a=c[c.length-1];
b=c[c.length-2];
d=c[c.length-3];
for(int i=0;i<c.length-3;i++) {
e[i+3]=c[i];
}
e[0]=d;
e[1]=b;
e[2]=a;
for(int i=0;i<c.length;i++)
System.out.print(e[i]);
}
}
package test5;
public class Zifutongji {
public static void main(String[] args) {
String str="ddejidsEFALDFfnef2357 3ed";
int m=0,n=0,k=0;
char[] c=str.toCharArray();
for(int i=0;i<str.length();i++)
{
if(c[i]>='a'&&c[i]<='z')
{
m++;
}
else if(c[i]>='A'&&c[i]<='Z')
{
n++;
}
else {
k++;
}
}
System.out.println("小写字母出现的次数: "+m);
System.out.println("大写字母出现的次数: "+n);
System.out.println("其他字符出现的字数: "+k);
}
}
标签:count ted gen image 输出 scan void 文字 info
原文地址:https://www.cnblogs.com/djhxxx/p/11594697.html