Tuesday 5 February 2019

7. How to check Even OR Odd using scanner in java.


Description:
Write a sample code to check Even OR Odd  using scanner in java.


Code:
?
1
2
3
4
5
6
7
8
9
10
import java.util.Scanner; public class Even_Odd_Number { public static void main(String[] args) { int x; System.out.println("Enter the Number:"); Scanner s=new Scanner(System.in); x=s.nextInt(); if (x%2==0) System.out.println("Number is Even"); else System.out.println("Number is Odd"); } }


Output:
Enter the Number:
12
Number is Even

No comments:

Post a Comment