-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcode_7.java
More file actions
32 lines (26 loc) · 867 Bytes
/
code_7.java
File metadata and controls
32 lines (26 loc) · 867 Bytes
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
package clong.jgsu;
import java.util.Scanner;
public class code_7 {
public static void main(String[] args) {
/**
* 输入一行字符,分别统计出其英文字母、空格、数字和其它字符的个数。
*/
System.out.println("请输入一行字符:");
Scanner sc = new Scanner(System.in);
String s = sc.nextLine();
char ss[] = s.toCharArray();
int str_sum = 0;
int int_sum = 0;
int other_sum = 0;
for(int i=0;i<ss.length;i++){
if(ss[i]>=48&&ss[i]<=57){
int_sum++;
}else if((ss[i]>=65&&ss[i]<=90)||(ss[i]>=97&&ss[i]<=122)){
str_sum++;
}else{
other_sum++;
}
}
System.out.println("char个数:"+str_sum+"数字个数:"+int_sum+"其他个数:"+other_sum);
}
}