Sunday, July 16, 2017

Write a program that accepts an input from a user and tells whether the number is even or odd.

/**
 * Created by Jo on 7/10/2017.
 * For more exercises and lessons, visit http://shegertech.blogspot.com/
 * Chapter 4, Exercise 1
 */

import java.util.Scanner;
public class Q1Solution {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int num = 0;
        System.out.print("Enter a number : ");
        num = in.nextInt();

        if (num%2==0)
            System.out.println(num+" is an even number");
        else
            System.out.println(num+ " is an odd number");

    }
}

Share: