Question
Recall that in Scala conditional expressions have the form: if(condition) consequent else alternative The equivalent expression in Java would be: condition? consequent: alternative For example:
Recall that in Scala conditional expressions have the form: if(condition) consequent else alternative The equivalent expression in Java would be: condition? consequent: alternative For example: scala> if(true) 10 else 20 res0: Int = 10 scala> (if(true) 2 else 3) * (if(false) 5 else 7) res1: Int = 14 1.
Problem: "Number Kingdoms" In numerology a number (i.e., an integer) belongs to one of several kingdoms. If it is an even integer bigger than 10, it belongs to kingdom 1, unless it is also divisible by 100, then it belongs to kingdom 2. Any number less than or equal to 10 belongs to the third kingdom. Otherwise, it is condemned to the lowly fourth kingdom. Implement a kingdom function: def kingdom(n: Int): Int = ??? Avoid using Boolean functions (&&, ||, !, ^) and definitions of additional names. Only use conditional expressions (if-else expressions).
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started