Created
August 13, 2012 13:49
-
-
Save Linusstrom/3340966 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class WordNgram{ | |
private int size; | |
private String[] words ={}; | |
public WordNgram(int size){ | |
this.size = size; | |
} | |
public WordNgram(int size, String words){ | |
this.size = size; | |
this.words = words.split(" "); | |
} | |
public String getWord(int size){ | |
String result = this.words[size - 1]; | |
if (result == null) { | |
System.out.println("index out of bounds"); | |
return ""; | |
} | |
return result; | |
} | |
public String toString(){ | |
if (words.length == 0){ | |
String value = ""; | |
for ( int n=0; n<size; n++) { | |
value = value + ","; | |
} | |
return value; | |
} | |
} | |
public static void main(String[] args) { | |
WordNgram w1 = new WordNgram(7); | |
System.out.println(w1); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment