-
Notifications
You must be signed in to change notification settings - Fork 0
/
A.java
70 lines (62 loc) · 1.41 KB
/
A.java
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/**
*
*/
package forbasic;
import java.util.Arrays;
import java.util.Scanner;
/**
* @author Administrator
* @title name
* @Date 2018年6月25日
* 用来统计一串字符中的字母。数字。空格的数量
*/
public class A {
public static void main(String args[]){
int numcount=0;
int charcount=0;
int spacecount=0;
int othercount=0;
Scanner sc=new Scanner(System.in);
System.out.println("请随意输入一串字符");
String a=sc.nextLine();
System.out.println(a);
char[] c=a.toCharArray();
for(int i=0;i<c.length;i++){
//汉字的unicode范围是:0x4E00~0x9FA5
if(Character.isLetter(c[i])&&!((c[i]>= 0x4e00)&&(c[i]<= 0x9fbb))){//字母
charcount++;
}
else if(Character.isDigit(c[i])){
numcount++;
}
else if(Character.isWhitespace(c[i])){
spacecount++;
}
else{
othercount++;
}
}
System.out.println("数字为:"+numcount+" "+"字母为:"+charcount+" "+"空格为:"+spacecount+" "+"其他为:"+othercount);
/*
int x=40;
if( x == 10 ){
System.out.print("Value of X is 10");
}
else if( x == 20 ){
System.out.print("Value of X is 20");
}
else if( x == 30 ){
System.out.print("Value of X is 30");
}else{
System.out.print("这是 else 语句");
}
*
*/
}
/**
*
*/
public A() {
// TODO Auto-generated constructor stub
}
}