笔试

/**
* 判断一个字符串是不是数字组成
* @param s 字符。
* @return
*/
public static boolean isDigits(String s){
if(s==null||s.length()==0)return false;
for(int i=0;i <s.length();i++){
if(!Character.isDigit(s.charAt(i)))return false;
}
return true;
}

 

 

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.Map;

/**
*@ author ajax_2003
*/
class Base {
public static void main(String[] args ) throws Exception {
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
Map<String, Integer> map = new HashMap<String, Integer>();
String str = null;

while (!(str = in.readLine()).equalsIgnoreCase("quit")) {
System.out.println("请输入数据, 输入quit退出");

if (map.get(str) == null) {
map.put(str, 1);
}
else {
map.put(str, map.get(str) + 1);
}
}
for (Object key : map.keySet().toArray()) {
System.out.println(key + " 出现: " + map.get(key) + " 次");
}
}
}
 

 

用HashMap来解决
假设单词不存在跨行的,每个单词用,. ;分割    

Java代码 复制代码
  1. import java.io.*;   
  2. import java.util.*;   
  3.   
  4. public class FindWord {   
  5.     public void countNum()throws IOException{   
  6.         BufferedReader br=null;   
  7. try{   
  8.     br= new BufferedReader(new FileReader("D://111.txt"));   
  9.             Map map= new HashMap();   
  10. for(String s=br.readLine(); s!=null; s=br.readLine()){   
  11.     StringTokenizer st= new StringTokenizer(s,",. ;");   
  12.     while(st.hasMoreTokens()){   
  13.         String temp=st.nextToken();   
  14.         if(map.containsKey(temp)){   
  15.     map.put(temp, new Integer((Integer)map.get(temp)+1));   
  16.                     }else{   
  17.         map.put(temp, new Integer(1));   
  18.                     }   
  19.                        
  20.                 }   
  21.             }   
  22. for(Iterator it=map.entrySet().iterator();it.hasNext();){   
  23. Map.Entry<String, Integer> entry=(Map.Entry<String, Integer>)it. next();           
  24. System.out.println(entry.getKey()+"-->"+entry.getValue());   
  25.             }   
  26.         }catch(Exception e){   
  27.             e.printStackTrace();       
  28.         }finally{   
  29.             br.close();        
  30.         }          
  31.     }   
  32. public static void main(String[] args)throws IOException{   
  33.     FindWord fw=new FindWord();   
  34.     fw.countNum();   
  35.     }   
  36.   
  37. }  

 

依次读每一行,然后判断是否有单词  
   
  BufferedInputStream   bis   =   ....   //   这里打开文件  
   
  String   key="单词";  
  String   line;   //   存储一行  
  int   count   =   0;   //   表示第几行  
   
  while((line=bis.readLine())!=null)  
  {  
      n++;  
      if(line.indexOf(key)!=(-1))   //   找到了  
          System.out.println("在第"   +   n   +   "行找到了单词。");  
  }   
   

 

* 计算递归的方法
* @param num
* @return
*/
public int Digui(int num){
if(num == 0){
num=1;
}else{
return num*Digui(num-1);
}
return num;
}

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值