import java.io.*;
public class Test{
public static void main(String[] args) throws Exception{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String str = br.readLine();
if(str == null) throw new Exception("");
char[] c = str.toCharArray();
int words = 0;
int ip = 0;
boolean wordflag = false;
for(int i=0;i
if((c[i]>='a' && c[i] <= 'z') || (c[i] >= 'A' && c[i] <= 'Z')){
if(wordflag) {
continue;
}else{
words++;
}
wordflag = true;
}else{
wordflag = false;
if(c[i] != ' ')
ip++;
}
}
System.out.println("words=" + words);
System.out.println("ip=" + ip);
for(int i=0;i
{
System.out.print("c["+i+"]="+c[i]);
}
}
}
本文介绍了一个使用Java编写的简单程序,该程序读取标准输入并统计英文单词数量及非空字符位置。通过解析输入字符串,程序能够识别出单词边界,并记录每个字符的位置。
2057

被折叠的 条评论
为什么被折叠?



