From 90dacfe424505525438069f756d9b08ae7281593 Mon Sep 17 00:00:00 2001 From: kriseattle Date: Mon, 7 Apr 2025 12:26:26 -0700 Subject: [PATCH 1/4] I completed the assignment --- src/Practice.java | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/src/Practice.java b/src/Practice.java index 89acfd9..812ce85 100644 --- a/src/Practice.java +++ b/src/Practice.java @@ -18,6 +18,10 @@ public class Practice { */ public static void printItems(String[] items) { // TODO: Implement this method here! + //use for loop to loop through every single item and print out + for (int i = 0; i < items.length; i++){ + System.out.println(items[i]); + } } /** @@ -45,7 +49,11 @@ public static void printItems(String[] items) { */ public static boolean moreThanDouble(int a, int b) { // TODO: Delete the dummy return statement and implement this method here! - return false; + if (a > b*2){ + return true; + } else { + return false; + } } @@ -71,8 +79,22 @@ public static boolean moreThanDouble(int a, int b) { */ public static boolean allStartWithA(String[] words) { // TODO: Delete the dummy return statement and implement this method here! - return false; - } + + //return true if array is empty + if (words.length == 0){ + return true; + } + + //use for loop to loop through every word to check if the word starts with A + for (int i = 0; i < words.length; i++){ + if (words[i].startsWith("A")){ + return true; + } + } + return false; + + } + public static void main(String[] args) { System.out.println(); From aea6ddd50673992a85eb649a4d4c2e4b535f6ecf Mon Sep 17 00:00:00 2001 From: kriseattle Date: Mon, 7 Apr 2025 13:20:10 -0700 Subject: [PATCH 2/4] I completed question 1 --- src/Practice.java | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/src/Practice.java b/src/Practice.java index 812ce85..77da2fe 100644 --- a/src/Practice.java +++ b/src/Practice.java @@ -49,11 +49,12 @@ public static void printItems(String[] items) { */ public static boolean moreThanDouble(int a, int b) { // TODO: Delete the dummy return statement and implement this method here! - if (a > b*2){ - return true; - } else { - return false; - } + // if (a > b*2){ + // return true; + // } else { + // return false; + // } + return false; } @@ -86,11 +87,11 @@ public static boolean allStartWithA(String[] words) { } //use for loop to loop through every word to check if the word starts with A - for (int i = 0; i < words.length; i++){ - if (words[i].startsWith("A")){ - return true; - } - } + // for (int i = 0; i < words.length; i++){ + // if (words[i].startsWith("A")){ + // return true; + // } + // } return false; } From 09e5580a4ee1b44ef581ca8c3368f632f0f32bda Mon Sep 17 00:00:00 2001 From: kriseattle Date: Mon, 7 Apr 2025 13:21:46 -0700 Subject: [PATCH 3/4] I completed question 2 --- src/Practice.java | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/Practice.java b/src/Practice.java index 77da2fe..3817986 100644 --- a/src/Practice.java +++ b/src/Practice.java @@ -49,12 +49,14 @@ public static void printItems(String[] items) { */ public static boolean moreThanDouble(int a, int b) { // TODO: Delete the dummy return statement and implement this method here! - // if (a > b*2){ - // return true; - // } else { - // return false; - // } - return false; + //use if statement to check if a values twice of b and return true + + if (a > b*2){ + return true; + } else { + return false; + } + } From 1c6026e86f7f660f491e1f3ef657a4262c19496c Mon Sep 17 00:00:00 2001 From: kriseattle Date: Mon, 7 Apr 2025 13:46:13 -0700 Subject: [PATCH 4/4] I completed question 3 with different method of for loop --- src/Practice.java | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/src/Practice.java b/src/Practice.java index 3817986..596cd83 100644 --- a/src/Practice.java +++ b/src/Practice.java @@ -50,7 +50,7 @@ public static void printItems(String[] items) { public static boolean moreThanDouble(int a, int b) { // TODO: Delete the dummy return statement and implement this method here! //use if statement to check if a values twice of b and return true - + if (a > b*2){ return true; } else { @@ -83,20 +83,21 @@ public static boolean moreThanDouble(int a, int b) { public static boolean allStartWithA(String[] words) { // TODO: Delete the dummy return statement and implement this method here! - //return true if array is empty - if (words.length == 0){ + //return true if array is empty, or + if (words == null || words.length == 0){ return true; } - //use for loop to loop through every word to check if the word starts with A - // for (int i = 0; i < words.length; i++){ - // if (words[i].startsWith("A")){ - // return true; - // } - // } + //use for loop to loop through every word to check if the word starts with A whether if it's A or a + for (String word : words){ + + if (!word.toUpperCase().startsWith("A")){ return false; - + } } + return true; + + } public static void main(String[] args) {