
Untitled
By: a guest on
Apr 25th, 2012 | syntax:
None | size: 1.08 KB | hits: 10 | expires: Never
//Ül 3
import java.util.*;
import java.io.*;
public class Sõnu {
public static void main(String[] args) throws FileNotFoundException{
FileInputStream failist = new FileInputStream (new File("C:/Users/Sirle/Documents/loe.txt"));
try {
Map<String, Integer> tekstiSonad=new HashMap<String, Integer>();
String tekst="";
while (true){
int number = failist.read();
if (number<0){
break;
}
else{
byte b = (byte) number;
if (b<33 || b>64){
char c=(char) b;
String s = Character.toString(c);
tekst+=s;
}
}
}
tekst=tekst.toLowerCase();
System.out.println(tekst);
String[] sonad=tekst.split(" ");
for (int i=0; i<sonad.length; i++){
if (tekstiSonad.containsKey(sonad[i])==false){
tekstiSonad.put(sonad[i],1);
}
else if (tekstiSonad.containsKey(sonad[i])==true){
tekstiSonad.put(sonad[i],tekstiSonad.remove(sonad[i])+1);
}
}
System.out.println("Sõnu tekstis: "+tekstiSonad.size());
System.out.println(tekstiSonad);
}
catch(IOException e){}
}
}