Back to Browse

Check If Number even or odd- Java Program | TOP 100 CODES |

245 views
May 12, 2024
6:15

The basic Java Program to check whether the given Number is Even or Odd. We use if-else Conditional Statement . Below is the code :- import java.util.Scanner; public class prob2{ public static void main(String[] args){ //Using Scanner class to take input from user Scanner scan = new Scanner(System.in); System.out.println("Enter num:- "); int num = scan.nextInt();//we use nextInt() to tak integer as an input //using a if else statement to check for even and odd if(num%2==0){ System.out.println("The given Number is Even."); }else{ System.out.println("The given Number is odd."); } } }

Download

1 formats

Video Formats

360pmp49.1 MB

Right-click 'Download' and select 'Save Link As' if the file opens in a new tab.

Check If Number even or odd- Java Program | TOP 100 CODES | | NatokHD