标签:mic 输出 str scan mamicode 实验目的 array 加密 用户输入
实验三 String类的应用
实验目的
掌握类String类的使用;
学会使用JDK帮助文档;
实验内容
package test;
public class One {
public static void main (String argsp[]) {
String str = "this is a test of java";
int count1 = 0;
for(int i = 0; i < str.length();i++) {
char c = str.charAt(i);
if(c == 's')
count1++;
}
System.out.println("s出现的次数为:"+count1);
int count2 = 0;
int index = 0;
String ch = "is";
while((index = str.indexOf(ch,index)) != -1) {
index = index + ch.length();
count2++;
}
System.out.println("子串\"is\"出现的次数为:"+count2);
int count3 = 0;
char a[] = str.toCharArray();
for(int i = 0; i < str.length(); i++) {
if(a[0] == 'i' && a[1] == 's' && a[2] == ' ')
count3++;
else if(a[i] == 'i' && a[i - 1] == ' ' && a[i + 1] == 's' && (a[i + 2] == ' '));
count3++;
}
System.out.println("单词\" is\"出现的次数为:"+count3);
String[] words = str.split(" ");
System.out.print("倒叙:");
for(int i = words.length-1; i >= 0; i--){
System.out.print(words[i]+" ");
}
}
}
package test;
import java.util.Scanner;
public class Two {
@SuppressWarnings("static-access")
public static void main (String args[]) {
System.out.println("加密请输入a,解密请输入b");
Scanner operate = new Scanner(System.in);
if(operate.nextLine().equals("b")) {
String str = operate.nextLine();
char b[] = str.toCharArray();
for(int j = 0; j < str.length();j++) {
b[j] = (char)(b[j] - 3);
}
str=str.valueOf(b);
System.out.println(str);
}
else{
String str = operate.nextLine();
char b[] = str.toCharArray();
for(int i = 0; i < str.length();i++) {
b[i] = (char)(b[i] + 3);
}
str=str.valueOf(b);
System.out.println(str);
}
}
}
package test;
public class Three {
public static void main(String args[]) {
String str = "ddejidsEFALDFfnef2357 3ed";
char a[] = str.toCharArray();
int count1 = 0, count2 = 0, count3 = 0;
for(int i = 0; i <= str.length() - 1;i++){
if(a[i] >= 'A' && a[i] <= 'Z'){
count1++;
}
else if(a[i] >= 'a' && a[i] <= 'z') {
count2++;
}
else {
count3++;
}
}
System.out.println("大写字母数为:"+count1);
System.out.println("小写字母数为:"+count2);
System.out.println("非英文字母数为:"+count3);
}
}
标签:mic 输出 str scan mamicode 实验目的 array 加密 用户输入
原文地址:https://www.cnblogs.com/20188382llz/p/11580665.html