黑马程序员技术交流社区
标题:
输入一行字符,分别统计出其中英文字母、空格、数字和...
[打印本页]
作者:
1334071171
时间:
2016-7-4 23:26
标题:
输入一行字符,分别统计出其中英文字母、空格、数字和...
输入一行字符,分别统计出其中英文字母、空格、数字和其它字符的个数。
作者:
代码是什么
时间:
2016-7-4 23:26
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("请输入字符串");
String s = sc.nextLine();
int a =0;
int b = 0;
int d=0;
int e = 0;
char [] arr = s.toCharArray();
for (char c : arr) {
if(c>='a'&&c<='z'||c>='A'&&c<='Z'){
a++;
}else if(c==' '||c=='\t'){
b++;
}else if(c>='0'&&c<='9'){
d++;
}else{
e++;
}
}
System.out.println("英文字母有"+a+"空格有"+b+"数字有"+d+"其他字符有"+e);
}
}
不好意思,刚才发的
作者:
代码是什么
时间:
2016-7-4 23:30
public static void main(String[] args) { Scanner sc = new Scanner(System.in); System.out.println("请输入字符串"); String s = sc.nextLine(); int a =0; int b = 0; int d=0; int e = 0; char [] arr = s.toCharArray(); for (char c : arr) { if(c>='a'&&c<='z'||c>='A'&&c<='Z'){ a++; }else if(c==' '||c=='\t'){ b++; }else if(c>='0'&&c<='9'){ d++; }else{ e++; } } System.out.println("英文字母有"+a+"空格有"+b+"数字有"+d+"其他字符有"+e); } }
作者:
lichmeng
时间:
2016-7-4 23:42
[size=14.3999996185303px]import java.util.Scanner;
[size=14.3999996185303px]public static void main(String[] args) {
[size=14.3999996185303px] Scanner sc = new Scanner(System.in);
[size=14.3999996185303px] System.out.println("输入字符串");
[size=14.3999996185303px] String s = sc.nextLine();
[size=14.3999996185303px] int a =0;
[size=14.3999996185303px] int b = 0;
[size=14.3999996185303px] int d=0;
[size=14.3999996185303px] int e = 0;
[size=14.3999996185303px] char [] arr = s.toCharArray();
[size=14.3999996185303px] for (char c : arr) {
[size=14.3999996185303px] if(c>='a'&&c<='z'||c>='A'&&c<='Z'){
[size=14.3999996185303px] a++;
[size=14.3999996185303px] }else if(c==' '||c=='\t'){
[size=14.3999996185303px] b++;
[size=14.3999996185303px] }else if(c>='0'&&c<='9'){
[size=14.3999996185303px] d++;
[size=14.3999996185303px] }else{
[size=14.3999996185303px] e++;
[size=14.3999996185303px] }
[size=14.3999996185303px] }
[size=14.3999996185303px] System.out.println("英文字母有"+a+"空格有"+b+"数字有"+d+"其他字符有"+e);
[size=14.3999996185303px] }
[size=14.3999996185303px]}
欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/)
黑马程序员IT技术论坛 X3.2