Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 25 additions & 1 deletion src/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,29 @@ public static void main(String[] args) {
// for you, but you can always add more by pressing <shortcut actionId="ToggleLineBreakpoint"/>.
System.out.println("i = " + i);
}
System.out.println("Is 'string' a unique word: " +isUnique("string"));
System.out.println("Is 'unique' a unique word: " + isUnique("unique"));
}
}

public static boolean isUnique(String word) throws StringIndexOutOfBoundsException
{
return isUnique(word, 0);
}

public static boolean isUnique(String word, int index) throws StringIndexOutOfBoundsException
{
char letter = word.charAt(index);
for (int i = 0; i < word.length(); i++)
{
if(letter == word.charAt(i) && i != index)
{
return false;
}
}
if (letter == word.charAt((word.length()-1)))
{
return isUnique(word, index+1);
}
return true;
}
}