Problem 3.01


Question 3.01: Write a program called CheckOddEven which prints "Odd Number" if the int variable “number” is odd, or “Even Number” otherwise. The program shall always print “bye!” before exiting.


Solution:

package com.company;
import java.util.Scanner;
public class Lab3Problem1 {

    public static void main(String[] args) {

        while(true){
        Scanner Obj = new Scanner(System.in);
        System.out.println("Enter your value: ");
        int n =Obj.nextInt();
        if(n % 2 == 0)
        {
            System.out.println("number is even");

        }
        else{
            System.out.println("number is Odd");
        }
            System.out.println("bye!");
        }

    }
}

Previous Post Next Post