Q:

Write a Scala program to check whether two given positive integers have the same last digit

0

Write a Scala program to check whether two given positive integers have the same last digit.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

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

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now