Computer Science, asked by choutu2624, 2 months ago

Write a Java program to accept a number and check the number is even or not. Prints 1 if the number is even or 0 if the number is odd.

Answers

Answered by BrainlyProgrammer
8

Answer:

import java.util.Scanner;

class EveOddPrint{

public static void main (String ar []){

Scanner sc=new Scanner (System.in);

System.out.println("Enter a number");

int a=sc.nextInt();

if(a%2==0)

System.out.println("1");

else

System.out.println("0");

}

}

Logic:-

  • Accept a number
  • Check if it is even or odd
  • if even, print 1
  • else print 0
Answered by purveshKolhe
3

\huge{ \green{ \boxed{ \red{ \mathfrak{answer \: : }}}}}

You may use the following program::

import java.util.Scanner;

public class Brainly {

public static void main(String[] args) {

Scanner sc = new Scanner(System.in);

int usin = sc.nextInt();

if (usin % 2 == 0) {

System.out.println("1");

}

else {

System.out.println("0");

}

}

}

Output???

Sample input :-- 2

Sample output :-- 1

Logic::

==> Takes input and stores it in variable named usin.

==> Checks whether it returns 0 as remainder after divided by 2. If yes, it prints "1" otherwise "0".

Hope It Helps You..

Similar questions