Kotlinlearncs.online LogoJava
Return to List

Solve: Species Switch Add Default

Created By: Ellen Spertus
/ Version: 2023.12.0

Add a default case setting result to "unknown".

public class Question {
public static void printCategory(String species) {
String result = "";
switch (species) {
case "cat":
case "dog":
result = "real";
break;
case "dragon":
result = "mythical";
break;
}
System.out.println("The category of " + species + " is " + result);
}
}

Related Lessons

Stuck? You may find these lessons helpful: