統計一個字串中大寫字母字元,小寫字母字元,數字字元出現的次數
阿新 • • 發佈:2020-12-09
package 專案五;
import java.util.Scanner;
public class 專案五 {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc = new Scanner(System.in);
System.out.println("請輸入字串: ");
String Line = sc .nextLine();
int f=0;
int g=1;
int h=0;
for(int c= 1 ;c<Line.length();c++) {
char ch = Line.charAt(c);
if(ch>='A' && ch<='Z') {
f++;
}else if(ch>='a' && ch<='z') {
g++;
}else if(ch>='0' && ch<='9') {
h++;
}
}
System.out.println("大寫字元有" +f+"個"+"小寫字元有"+g+"個"+"數字有"+h+"個");
}
}