问题描述:
从键盘数入若干文字,最后输入的一行"end"代表结束标记。
统计该段文字中英文字母的个数
将其中的所有单词the全部改为a,输出结果
将该段文字所有的数字串找出来输出
备注:
编程语言:JAVA
编译器:EverEdit
编译环境:JDK1.8.0_191
操作系统:windows 10
源代码:
//字符串的处理(String类,StringBuffer类)
/*测试数据:
1001 张三 the desk
李四 2019 04 03 the cup
22 48 王二 the 8356 thesleep
end
*/
import java.io.*;
class Main{
public static void main(String args[]){
//从键盘数入若干文字,最后输入的一行"end"代表结束标记
String s="";
String a[] = new String[100];//声明数组并规定空间
int n=0;
while(true){
try{
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
s=in.readLine();//读一行字符
if(s.equals("end"))//equals()判断字符串是否相等:a,b必为字符串 ,a和b相等(a.equals(b))
break;
}catch(IOException e){ }
a[n]=s;
n++;
}
//统计该段文字中英文字母的个数
int number=0;
for(int i=0;i
for(int k=0;k
char x = a[i].charAt(k);//返回指定位置的字符
if((x >= ‘a‘ && x <= ‘z‘)||(x >= ‘A‘ && x <= ‘Z‘))
number++;
}
}
System.out.println();
System.out.println(number);
System.out.println();
//将其中的所有单词the全部改为a,输出结果
for(int i=0;i
s=a[i].replaceAll("the","a");//用a替换the
System.out.println(s);
}
//将该段文字所有的数字串找出来输出
StringBuffer stb = new StringBuffer();
for(int i=0;i
for(int k=0;k