import java.util.Scanner;
public class AppendTest {
public static void main(String[] args) {
// fun1();
// fun2();
// fun3();
Scanner sc = new Scanner(System.in);
System.out.println("Please input the string:");
String str = sc.nextLine();
int countU = 0;
int countL = 0;
int countD = 0;
int countO = 0;
// 遍历字符串
for (int index = 0; index < str.length(); index++) {
char ch = str.charAt(index);
if (Character.isUpperCase(ch)) {
// System.out.println("isUpperCase");
countU++;
} else if (Character.isLowerCase(ch)) {
// System.out.println("isLowerCase");
countL++;
} else if (Character.isDigit(ch)) {
// System.out.println("isDigit");
countD++;
} else {
// System.out.println("isOther");
countO++;
}
}
System.out.println("countU=" + countU + ",countL=" + countL + ",countD=" + countD);
}
private static void fun3() {
Scanner sc = new Scanner(System.in);
System.out.println("Please input the string:");
String str = sc.nextLine();
StringBuffer sb = new StringBuffer(str);
String str2 = sb.reverse().toString();
// System.out.println("str="+str);
// System.out.println("str2="+str2);
boolean equals = str.equals(str2);
// System.out.println(equals);
if (equals) {
System.out.println("Equal.");
} else {
System.out.println("Not equal.");
}
}
private static void fun2() {
Scanner sc = new Scanner(System.in);
System.out.println("Please input the string:");
String str = sc.nextLine();
System.out.println("Reverse:");
System.out.println(new StringBuffer(str).reverse());
}
private static void fun1() {
String s = "S";
String b = "B";
StringBuffer sb = new StringBuffer(s).append(b);
System.out.println(sb);
}
}
|
|