Write a Scala program to check whether two given positive integers have the same last digit.
object scala_basic { def test(x: Int, y: Int): Boolean = { Math.abs(x % 10) == Math.abs(y % 10); } def main(args: Array[String]): Unit = { println("Result: " + test(123, 456)); println("Result: " + test(12, 512)); println("Result: " + test(7, 87)); println("Result: " + test(12, 45)); } }
Sample Output:
Result: false Result: true Result: true Result: false
total answers (1)
start bookmarking useful questions and collections and save it into your own study-lists, login now to start creating your own collections.
Sample Output:
need an explanation for this answer? contact us directly to get an explanation for this answer