Saturday, August 19, 2017

Odd and Even Number Checker Using Scala

I wrote this simple program to ask the user to give a number and then our program will determine if the given number by our user is an ODD or EVEN number. I am using Scala as my programming language in this sample program. I am still a beginner in Scala programming, learning Scala is much easier it resembles Java programming language in many language syntax and features. I hope you will find my work useful. Thank you.

I hope you will find my work useful and beneficial. If you have some questions about programming, about my work please send mu an email at jakerpomperada@gmail.com and jakerpomperada@yahoo.com. People here in the Philippines can contact me at  my mobile number 09173084360.


Thank you very much and Happy Programming.







Sample Program Output


Program Listing

OddEven.scala

// Written By: Mr. Jake R. Pomperada, MAED-IT
// Tool : Scala
// IDE  : IntelliJ IDEA Community Version 2017.2
// Date : August 19, 2017   Saturday
// Country : Philippines


import java.util.Scanner;

object OddEven {

  def main(args: Array[String]) {

    var input = new Scanner(System.in);

    def isEven(number: Int) = number % 2 == 0
    def isOdd(number: Int) = !isEven(number)

    print("\n\n");
    print("Odd and Even Number Checker Using Scala");
    print("\n\n");
    print("Written By: Mr. Jake R. Pomperada, MAED-IT");
    print("\n\n");
    print("Enter a Number : ");

    var num_value = input.nextInt();

    if (isEven(num_value)) {
      print("\n\n");
      print("The given number " + num_value + " is an EVEN number.");
      print("\n\n");
    }
    else if  (isOdd(num_value))  {
      print("\n\n");
      print("The given number " + num_value + " is an ODD number.");
      print("\n\n");
    }

    print("\t END OF PROGRAM");
    print("\n\n");
  }
}




No comments:

Post a Comment