-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcharAt_String.java
More file actions
52 lines (45 loc) · 1.52 KB
/
charAt_String.java
File metadata and controls
52 lines (45 loc) · 1.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
/*
* @由于个人水平有限, 难免有些错误, 还请指点:
* @Author: cpu_code
* @Date: 2020-09-12 21:44:25
* @LastEditTime: 2020-09-12 21:54:31
* @FilePath: \java\javaAPI\String\charAt_String.java
* @Gitee: [https://gitee.com/cpu_code](https://gitee.com/cpu_code)
* @Github: [https://github.com/CPU-Code](https://github.com/CPU-Code)
* @CSDN: [https://blog.csdn.net/qq_44226094](https://blog.csdn.net/qq_44226094)
* @Gitbook: [https://923992029.gitbook.io/cpucode/](https://923992029.gitbook.io/cpucode/)
*/
package javaAPI.String;
import java.util.Scanner;
public class charAt_String {
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
System.out.println("输入数 :");
String s = sc.nextLine();
int bigCount = 0;
int smallCount = 0;
int numberCount = 0;
for(int i = 0; i < s.length(); i++){
char ch = s.charAt(i);
if(ch >= 'A' && ch <= 'Z'){
bigCount++;
} else if(ch >= 'a' && ch <= 'z'){
smallCount++;
} else if(ch >= '0' && ch <= '9'){
numberCount++;
} else {
System.out.println("字符" + ch + "非法");
}
}
System.out.println("大写字符" + bigCount + "个");
System.out.println("小写字符" + smallCount + "个");
System.out.println("数字字符" + numberCount + "个");
}
}
/*
输入数 :
CpuCode12
大写字符2个
小写字符5个
数字字符2个
*/