Computer Science, asked by chauhanpranav2006, 1 month ago

write a program in Java to check whether the number is even or odd enter three numbers 5,12,4 sample output smallest number is four it is even​

Answers

Answered by s16497aDHAIRIYA2561
1

Answer:

MARK ME AS BRAINLIST

________________________

In this program, you'll learn to check if a number entered by an user is even or odd. This will be done using if...else statement and ternary operator in Java.

To understand this example, you should have the knowledge of the following Java programming topics:

Java if...else Statement

Java Scanner Class

__________________________

Example 1: Check whether a number is even or odd using if...else statement

import java.util.Scanner;

public class EvenOdd {

public static void main(String[] args) {

Scanner reader = new Scanner(System.in);

System.out.print("Enter a number: ");

int num = reader.nextInt();

if(num % 2 == 0)

System.out.println(num + " is even");

else

System.out.println(num + " is odd")

__________________________

In the above program, a Scanner object, reader is created to read a number from the user's keyboard. The entered number is then stored in a variable num.

Now, to check whether num is even or odd, we calculate its remainder using % operator and check if it is divisible by 2 or not.

For this, we use if...else statement in Java. If num is divisible by 2, we print num is even. Else, we print num is odd.

We can also check if num is even or odd by using ternary operator in Java.

__________________________

Answered by soumadeepnaskar559
0

Answer:

import java.util.*;

public class A1;

{

public static void main (String args[])

{

Scanner sc=new Scanner (System.in);

int a=sc.nextInt();

System.out.prinln("ENTER THE NUMBERS");

if(a%2==0)

System.out.println("THE NUMBER IS EVEN NUMBER");

else

System.out.println("THE NUMBER IS ODD NUMBER");

}

}

Similar questions