Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Apr 25th, 2012  |  syntax: None  |  size: 1.08 KB  |  hits: 10  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. //Ül 3
  2. import java.util.*;
  3. import java.io.*;
  4.  
  5. public class Sõnu {
  6.         public static void main(String[] args) throws FileNotFoundException{
  7.                 FileInputStream failist = new FileInputStream (new File("C:/Users/Sirle/Documents/loe.txt"));
  8.                 try {
  9.                         Map<String, Integer> tekstiSonad=new HashMap<String, Integer>();
  10.                         String tekst="";
  11.                         while (true){
  12.                                 int number = failist.read();
  13.                                 if (number<0){
  14.                                         break;
  15.                                 }
  16.                                 else{
  17.                                         byte b = (byte) number;
  18.                                         if (b<33 || b>64){
  19.                                                 char c=(char) b;
  20.                                                 String s = Character.toString(c);
  21.                                                 tekst+=s;
  22.                                         }
  23.                                 }      
  24.                         }
  25.                         tekst=tekst.toLowerCase();
  26.                         System.out.println(tekst);
  27.                         String[] sonad=tekst.split(" ");
  28.                         for (int i=0; i<sonad.length; i++){
  29.                                 if (tekstiSonad.containsKey(sonad[i])==false){
  30.                                         tekstiSonad.put(sonad[i],1);
  31.                                 }
  32.                                 else if (tekstiSonad.containsKey(sonad[i])==true){
  33.                                         tekstiSonad.put(sonad[i],tekstiSonad.remove(sonad[i])+1);
  34.                                 }
  35.                         }
  36.                         System.out.println("Sõnu tekstis: "+tekstiSonad.size());
  37.                         System.out.println(tekstiSonad);
  38.                 }
  39.                 catch(IOException e){}
  40.         }
  41. }