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
27 changes: 27 additions & 0 deletions src/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,32 @@ public static void main(String[] args) {
// for you, but you can always add more by pressing <shortcut actionId="ToggleLineBreakpoint"/>.
System.out.println("i = " + i);
}

// quick test
boolean result = isUnique("always");
System.out.println(result);
}

public static boolean isUnique(String word)
{
// if string is empty, consider it unique
if(word.isEmpty())
{
return true;
}
// nested for loop to scan through string to check if all chars are unique
for(int i=0; i<word.length(); i++)
{
for (int j = 0; j < word.length(); j++)
{
if(word.charAt(i)==word.charAt(j) && i!=j)
{
return false;
}
}

}
// return true if no duplicates are found
return true;
}
}