From 7f7aa3b40abeed024fb2fa1afc410b3ef9b181f6 Mon Sep 17 00:00:00 2001 From: Everett Hanke Date: Tue, 9 Jan 2024 09:55:59 -0800 Subject: [PATCH 1/5] test commit --- .idea/vcs.xml | 6 ++++++ src/Main.java | 5 +++++ 2 files changed, 11 insertions(+) create mode 100644 .idea/vcs.xml diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..35eb1dd --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/src/Main.java b/src/Main.java index 930198c..ec6cb40 100644 --- a/src/Main.java +++ b/src/Main.java @@ -11,5 +11,10 @@ public static void main(String[] args) { // for you, but you can always add more by pressing . System.out.println("i = " + i); } + System.out.println(isUnique("String")); + } + public static boolean isUnique(String word) + { + return true; } } \ No newline at end of file From fa685e8d646215fc8325df9f428be20c899a9e0c Mon Sep 17 00:00:00 2001 From: Everett Hanke Date: Tue, 9 Jan 2024 10:50:17 -0800 Subject: [PATCH 2/5] test commit --- src/Main.java | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/src/Main.java b/src/Main.java index ec6cb40..706f1a1 100644 --- a/src/Main.java +++ b/src/Main.java @@ -1,3 +1,5 @@ +import java.util.Hashtable; + //TIP To Run code, press or // click the icon in the gutter. public class Main { @@ -11,10 +13,27 @@ public static void main(String[] args) { // for you, but you can always add more by pressing . System.out.println("i = " + i); } - System.out.println(isUnique("String")); + System.out.println("Is 'string' a unique word: "+isUnique("string")); //prints true + System.out.println("Is 'unique' a unique word: " + (isUnique("unique"))); //prints false + } + public static boolean isUnique(String word) throws StringIndexOutOfBoundsException + { + return isUnique(word, 0); } - public static boolean isUnique(String word) + private 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; } } \ No newline at end of file From 7545b71c16166f8355bd9a0a67781aa860f2d5d6 Mon Sep 17 00:00:00 2001 From: Everett Hanke Date: Tue, 9 Jan 2024 10:51:09 -0800 Subject: [PATCH 3/5] Final Unique Push --- src/Main.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/Main.java b/src/Main.java index 706f1a1..39ec99c 100644 --- a/src/Main.java +++ b/src/Main.java @@ -16,6 +16,13 @@ public static void main(String[] args) { System.out.println("Is 'string' a unique word: "+isUnique("string")); //prints true System.out.println("Is 'unique' a unique word: " + (isUnique("unique"))); //prints false } + + /** + * isUnique method + * @param word + * @return boolean + * @throws StringIndexOutOfBoundsException + */ public static boolean isUnique(String word) throws StringIndexOutOfBoundsException { return isUnique(word, 0); From fd054112eff53a6974451c0470d2a6b6bc20c180 Mon Sep 17 00:00:00 2001 From: Everett Hanke Date: Tue, 9 Jan 2024 12:04:57 -0800 Subject: [PATCH 4/5] Final Unique Push --- src/Main.java | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/Main.java b/src/Main.java index 39ec99c..5709bda 100644 --- a/src/Main.java +++ b/src/Main.java @@ -15,6 +15,8 @@ public static void main(String[] args) { } System.out.println("Is 'string' a unique word: "+isUnique("string")); //prints true System.out.println("Is 'unique' a unique word: " + (isUnique("unique"))); //prints false + System.out.println("Is 'unique' a unique word: " + (isUnique("Hello"))); //prints false + } /** @@ -30,14 +32,17 @@ public static boolean isUnique(String word) throws StringIndexOutOfBoundsExcepti private static boolean isUnique(String word, int index) throws StringIndexOutOfBoundsException { char letter = word.charAt(index); - for (int i = 0; i < word.length(); i++) + //String newWord = word.substring(index, word.length()-1); + //System.out.println(newWord); + for (int i = index; i < word.length(); i++) { + //System.out.println(letter + " == " + word.charAt(i)); if (letter == word.charAt(i) && i != index) { return false; } } - if (letter == word.charAt(word.length()-1)) + if (letter != word.charAt(word.length()-1)) { return isUnique(word, index+1); } From 4475646f78a81cef5742f9911c7003d111c2fdff Mon Sep 17 00:00:00 2001 From: Everett Hanke Date: Tue, 9 Jan 2024 13:16:57 -0800 Subject: [PATCH 5/5] Final Unique Push 2.0 --- src/Main.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Main.java b/src/Main.java index 5709bda..9d4945c 100644 --- a/src/Main.java +++ b/src/Main.java @@ -15,7 +15,7 @@ public static void main(String[] args) { } System.out.println("Is 'string' a unique word: "+isUnique("string")); //prints true System.out.println("Is 'unique' a unique word: " + (isUnique("unique"))); //prints false - System.out.println("Is 'unique' a unique word: " + (isUnique("Hello"))); //prints false + System.out.println("Is 'hello' a unique word: " + (isUnique("hello"))); //prints false }