Skip to content

Commit

Permalink
Add null challenges
Browse files Browse the repository at this point in the history
  • Loading branch information
bowbahdoe committed Sep 22, 2024
1 parent 0bb8ed8 commit ac384a6
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions src/null/challenges.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,20 +93,33 @@ void main() {

## Challenge 5.

Without changing anything in the `main` method, make the `howBig`
Without changing anything in the `main` method, make the `bigness`
method not throw a `NullPointerException` and still have the "correct"
behavior for non-null inputs.

```java,editable
int howBig(String letters) {
String bigness(String letters) {
int bigness = 0;
for (int i = 0; i < letters.length(); i++) {
bigness++;
}
return bigness;
if (bigness < 5) {
return "small";
}
else if (bigness < 10) {
return "medium"
}
else {
return "big";
}
}
void main() {
System.out.println(
bigness("bore")
);
System.out.println(
bigness("boiler")
);
Expand All @@ -119,6 +132,10 @@ void main() {
bigness("knower")
);
System.out.println(
bigness("chrysanthemum")
);
System.out.println(
bigness(null)
);
Expand Down

0 comments on commit ac384a6

Please sign in to comment.