标签:统计 字符 next ext for java 解密 使用 count
package testreport;
public class testreport301 {
public static void main(String[] args) {
String str = "this is test of java";
int count = 0;
int sum = 0;
int num = 0;
String[] v = str.split(" ");
for (int a = 0; a < str.length(); a++) {
char c = str.charAt(a);
if (c == 's') {
count++;
}
}
for (int n = 0; n < str.length() - 2; n++) {
String z = str.substring(n, n + 2);
if (z.equals("is")) {
sum++;
}
}
for (int m = 0; m < str.length() - 4; m++) {
String z = str.substring(m, m + 4);
if (z.equals(" is ")) {
num++;
}
}
System.out.println("字符串中字母“s”出现的次数:" + count);
System.out.println("字符串中子串“is”出现的次数:" + sum);
System.out.println("字符串中单词“is”出现的次数:" + num);
System.out.print("倒序输出1:");
for (int j = str.length() - 1; j > 0; j--) {
char zf = str.charAt(j);
System.out.print(zf);
}
System.out.println();
System.out.print("倒序输出2:");
for (int k = 4; k >= 0; k--) {
System.out.print(v[k]+" ");
}
}
}
package testreport;
import java.util.Scanner;
public class testreport302 {
public static void main(String[] args) {
System.out.println("请输入字符串:");
Scanner sc=new Scanner(System.in);
String str1=sc.next();
char[] c= str1.toCharArray();
System.out.println("加密后的结果");
for(char x:c){
System.out.print((char) (x+3));
}
}
}
package testreport;
import java.util.Scanner;
public class testreport303 {
public static void main(String[] args)
{
Scanner s=new Scanner(System.in);
String str="ddejidsEFALDFfnef2357 3ed";
System.out.println("大写字母有:");
for (int i = 0; i < str.length(); i++) {
if (str.charAt(i) >= 'A' && str.charAt(i) <= 'Z') {
System.out.print(str.charAt(i));
}
}
System.out.println();
System.out.println("小写字母有:");
for (int j= 0; j < str.length(); j++) {
if (str.charAt(j) >= 'a' && str.charAt(j) <= 'z') {
System.out.print(str.charAt(j));
}
}
System.out.println();
System.out.println("其他字符有:");
for (int k= 0; k < str.length(); k++){
if(str.charAt(k)<'A'||str.charAt(k)>'z')
System.out.print(str.charAt(k));
}
}
}
标签:统计 字符 next ext for java 解密 使用 count
原文地址:https://www.cnblogs.com/94ha-xc/p/11588707.html