Search the Community
Showing results for tags 'codingbat'.
Found 2 results
-
Alright, so - the problem! (These are using loops) Given a string, return a string where for every char in the original, there are two chars. doubleChar("The") → "TThhee" doubleChar("AAbb") → "AAAAbbbb" doubleChar("Hi-There") → "HHii--TThheerree" [CODE] public String doubleChar(String str) { String answer = ""; for (int i = 0; i<str.length(); i++) { str.substring(i, i+1); } for (int x = 0; x < str.length(); x++) { answer += str; } return answer; } [/CODE] The output so far is like this hihi instead of hhii :( Also, don't know where to start on this problem.. Return the number of times that the string "hi" appears anywhere in the given string. countHi("abc hi ho") → 1 countHi("ABChi hi") → 2 countHi("hihi") → 2 I DISCOVERED WHILE LOOPS AND IM JIZZING K LOL Return true if the given string contains an appearance of "xyz" where the xyz is not directly preceeded by a period (.). So "xxyz" counts but "x.xyz" does not. xyzThere("abcxyz") → true xyzThere("abc.xyz") → false xyzThere("xyz.abc") → true [CODE] public boolean xyzThere(String str) { String other = "xyz"; String otherz = "xxyz"; while (!str.contains(other) || str.contains(otherz)) { return false; } return true; } [/CODE] ^ I get most right but I still get like a couple wrong :/ My teacher sucks ass at teaching so I don't really know how to do these blargh... Just need help getting started...
-
Can someone please explain to me why this is wrong? [CODE]public boolean makeBricks(int small, int big, int goal) { int inch = big*5; if(goal >= inch) return(goal-inch <= small); else return(small >= goal || (goal-small)%5 == 0); }[/CODE] the problem can be found at [url]http://codingbat.com/prob/p183562[/url]