Set实现元音统计小程序
来源:互联网 发布:centos网络配置命令 编辑:程序博客网 时间:2024/06/05 19:41
import java.io.FileInputStream;
import java.io.InputStream;
import java.util.Arrays;
import java.util.Collection;
import java.util.TreeSet;
class WordFinder{
private Collection<Character> set=new TreeSet<Character>(){
private static final long serialVersionUID = 1L;
{
add('a') ;
add('e') ;
add('i') ;
add('o') ;
add('u') ;
}
} ;
private String[] strArray=null ;
public WordFinder() {
try {
InputStream is=new FileInputStream("c:\\SetTest.java") ;
int length=is.available() ;
byte []bt=new byte[length] ;
is.read(bt) ;
strArray=new String(bt).split(" ") ;
System.out.println(Arrays.toString(strArray));
} catch (Exception e) {
e.printStackTrace();
}
}
public int find(){
int num=0 ;
for(String str:strArray)
{
for(Character c:set){
if(str.indexOf(c)!=-1){
num++ ;
continue ;
}
}
}
return num ;
}
}
public class Finder {
public static void main(String[]agrs){
WordFinder f=new WordFinder() ;
System.out.println("元音个数:"+f.find());
}
}
import java.io.InputStream;
import java.util.Arrays;
import java.util.Collection;
import java.util.TreeSet;
class WordFinder{
private Collection<Character> set=new TreeSet<Character>(){
private static final long serialVersionUID = 1L;
{
add('a') ;
add('e') ;
add('i') ;
add('o') ;
add('u') ;
}
} ;
private String[] strArray=null ;
public WordFinder() {
try {
InputStream is=new FileInputStream("c:\\SetTest.java") ;
int length=is.available() ;
byte []bt=new byte[length] ;
is.read(bt) ;
strArray=new String(bt).split(" ") ;
System.out.println(Arrays.toString(strArray));
} catch (Exception e) {
e.printStackTrace();
}
}
public int find(){
int num=0 ;
for(String str:strArray)
{
for(Character c:set){
if(str.indexOf(c)!=-1){
num++ ;
continue ;
}
}
}
return num ;
}
}
public class Finder {
public static void main(String[]agrs){
WordFinder f=new WordFinder() ;
System.out.println("元音个数:"+f.find());
}
}
- Set实现元音统计小程序
- 统计元音
- 统计元音
- 统计元音
- 统计元音
- 统计元音
- 统计元音
- 统计元音
- 统计元音
- 统计元音
- 统计元音
- 统计元音
- 统计元音
- 统计元音
- 统计元音
- 统计元音
- 统计元音
- 统计元音
- C++11中正则表达式测试
- 线程交互
- 昨晚上闭路电视没信号了
- 关于ubuntu和win7双系统使用的问题
- 模版文件 2440INIT.S
- Set实现元音统计小程序
- 异常:Invocation of com.google.gwt.user.tools.WebAppCreator failed. See the error log for more details
- VC/MFC结束程序进程时删除程序系统托盘中的图标
- [线段树+离散化]LightOJ 1089 - Points in Segments (II)
- TCP三次握手
- 关闭1433端口
- 程序员编程生产力相差10倍意味着什么?
- UART通信协议
- Fatal error: Cannot redeclare scandir()