Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialLeen Leenaerts
1,096 PointsWhat is wrong with my code?
<p>
public String getSandwich(String str) {
// remove first bread
int i = 0;
String bread1Removed = "";
while (i<(str.length()-9) && bread1Removed == "") {
if (str.substring(i,i+5).equals("bread")){
bread1Removed = str.substring(i+5);
}
i++;
}
// remove second bread
i = bread1Removed.length()-5;
String bread2Removed = "";
while (i>0 && bread2Removed == "") {
if (str.substring(i,i+5).equals("bread")){
bread2Removed = bread1Removed.substring(0,i);
}
i--;
}
return bread2Removed;
}
</p>
1 Answer
Leen Leenaerts
1,096 PointsFound it finally, just forgot to change the string in the if statement, how can i be this stupid :o
Michael Hess
24,512 PointsIt happens to all of us. Keep up the good work!
Kedious Mutandwa
4,929 Pointsthats being a programmer
Leen Leenaerts
1,096 PointsLeen Leenaerts
1,096 Pointsexercise from http://codingbat.com/prob/p129952
if i run it i get the wrong outcome works for breadbreadbreadbread but not for breadjambread.
The problem should be in // remove second bread