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 trialThandolwethu Bhebhe
1,417 PointsCreate a public method named getRemainingCharacterCount that returns an int showing how many characters are left
cant get this to work, its showing no error... i think theres no syntax error but the login isnt what they want... maybe i dont get the question. What am i doing wrong
public class Tweet {
final static public int MAX_CHARS=140;
private String text;
public int getRemainingCharacterCount(){
int remainingchars=MAX_CHARS-text.length();
while(remainingchars<= MAX_CHARS){
System.out.printf("You have %d character left",remainingchars);
}
return remainingchars;
}
public Tweet(String text) {
this.text = text;
}
public String getText() {
return text;
}
public void setText(String text) {
this.text = text;
}
}
2 Answers
Florian Tönjes
Full Stack JavaScript Techdegree Graduate 50,856 PointsHi Thandolwethu,
your while loop will run endlessly if the character limit is not reached, because the remaining chars will always be less or equal to MAX_CHARS. Just replace the "while" with an "if" statement and you will be fine.
Kind Regards, Florian
Thandolwethu Bhebhe
1,417 PointsThanks Florian, whenever I added shorthand increment/decrement notations it would give values that are way off. To solve if all i did was remove everything inside the method except the return statement and it worked.