Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.lang.String;
- import java.util.Scanner;
- public class Learn {
- public static void BOWVocabulary(String [] words,String [] uniquewords,int [] frequency){
- uniquewords[0]=words[0];frequency[0]=1;
- for (int i = 0; i < words.length; i++) { {if(i==0){continue;};
- for (int j = 0; j < words.length; j++) {
- if(words[i].equals(uniquewords[j]))
- frequency[j]=frequency[j]+1;
- }
- uniquewords[i]=words[i];
- frequency[i]++;
- }
- }
- }
- public static void main(String [] args){
- Scanner input = new Scanner(System.in);
- System.out.print("Enter a text (press enter to stop): ");
- String text=input.nextLine();
- String[] words = text.split("\\s+");
- int len=words.length;
- String[] uniquewords = new String[len];
- //array to save frequency
- int [] frequency = new int[len];
- BOWVocabulary(words,uniquewords,frequency);
- for (int i = 0; i <len; i++) {
- System.out.println(uniquewords[i]+" "+frequency[i]);
- }
- }}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement