What does the programmer what to find out from the following

What does the programmer what to find out from the following algorithm: IF 2*(X 2) = X THEN BEGIN EVEN:= 1 END IF 2*(X 2) X THEN BEGIN ODD:= 1 END

Solution

Program:

import java.util.Scanner;
class Algorithm
{
public static void main(String args[])
{
int x,z=1; // Here we are initializing x,z are integer variables
Scanner in = new Scanner(System.in); // scanning input by the user
System.out.println(\"Please enter the value of x : \");
x = in.nextInt(); // reading input from the user
if(2*(x/2)==x) // checking the condition if total value is equals to entered value of x
{
  System.out.println(\"Value is EVEN:= \"+z);
}
else if(2*(x/2)<x) // checking the condition if total value is less than to the entered value of x
{
    System.out.println(\"Value is ODD:= \"+z);
}

else if(2*(x/2)>x) // checking the condition if total value is greater than to the entered value of x
{
System.out.println(\"Value is ODD:= \"+z);
}
}
}

Output:

Please enter the value of x : 6

value is EVEN :=1

 What does the programmer what to find out from the following algorithm: IF 2*(X 2) = X THEN BEGIN EVEN:= 1 END IF 2*(X 2) X THEN BEGIN ODD:= 1 ENDSolutionProgr

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site