{"id":1339,"date":"2022-03-03T07:05:09","date_gmt":"2022-03-03T07:05:09","guid":{"rendered":"https:\/\/mdr.foobrdigital.com\/?p=1339"},"modified":"2022-03-03T07:05:09","modified_gmt":"2022-03-03T07:05:09","slug":"check-even-or-odd","status":"publish","type":"post","link":"https:\/\/mudassirbackup.infinitycodestudio.com\/index.php\/2022\/03\/03\/check-even-or-odd\/","title":{"rendered":"Check Even or Odd"},"content":{"rendered":"\n<pre class=\"wp-block-code\"><code>import java.util.Scanner;\n\npublic class EvenOdd {\n\n    public static void main(String&#91;] args) {\n\n        Scanner reader = new Scanner(System.in);\n\n        System.out.print(\"Enter a number: \");\n        int num = reader.nextInt();\n\n        if(num % 2 == 0)\n            System.out.println(num + \" is even\");\n        else\n            System.out.println(num + \" is odd\");\n    }\n}<\/code><\/pre>\n\n\n\n<p><strong>Output<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><samp>Enter a number: 12\n12 is even<\/samp><\/code><\/pre>\n\n\n\n<p>In the above program, a&nbsp;<code>Scanner<\/code>&nbsp;object,&nbsp;<code>reader<\/code>&nbsp;is created to read a number from the user&#8217;s keyboard. The entered number is then stored in a variable&nbsp;<var>num<\/var>.<\/p>\n\n\n\n<p>Now, to check whether&nbsp;<var>num<\/var>&nbsp;is even or odd, we calculate its remainder using&nbsp;<code>%<\/code>&nbsp;operator and check if it is divisible by&nbsp;<code>2<\/code>&nbsp;or not.<\/p>\n\n\n\n<p>For this, we use&nbsp;<code>if...else<\/code>&nbsp;statement in Java. If&nbsp;<var>num<\/var>&nbsp;is divisible by&nbsp;<code>2<\/code>, we print&nbsp;<var>num<\/var>&nbsp;is even. Else, we print&nbsp;<var>num<\/var>&nbsp;is odd.<\/p>\n\n\n\n<p>We can also check if&nbsp;<var>num<\/var>&nbsp;is even or odd by using ternary operator in Java.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Output In the above program, a&nbsp;Scanner&nbsp;object,&nbsp;reader&nbsp;is created to read a number from the user&#8217;s keyboard. The entered number is then stored in a variable&nbsp;num. Now, to check whether&nbsp;num&nbsp;is even or odd, we calculate its remainder using&nbsp;%&nbsp;operator and check if it is divisible by&nbsp;2&nbsp;or not. For this, we use&nbsp;if&#8230;else&nbsp;statement in Java. If&nbsp;num&nbsp;is divisible by&nbsp;2, we print&nbsp;num&nbsp;is [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[350],"tags":[],"_links":{"self":[{"href":"https:\/\/mudassirbackup.infinitycodestudio.com\/index.php\/wp-json\/wp\/v2\/posts\/1339"}],"collection":[{"href":"https:\/\/mudassirbackup.infinitycodestudio.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mudassirbackup.infinitycodestudio.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mudassirbackup.infinitycodestudio.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mudassirbackup.infinitycodestudio.com\/index.php\/wp-json\/wp\/v2\/comments?post=1339"}],"version-history":[{"count":0,"href":"https:\/\/mudassirbackup.infinitycodestudio.com\/index.php\/wp-json\/wp\/v2\/posts\/1339\/revisions"}],"wp:attachment":[{"href":"https:\/\/mudassirbackup.infinitycodestudio.com\/index.php\/wp-json\/wp\/v2\/media?parent=1339"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mudassirbackup.infinitycodestudio.com\/index.php\/wp-json\/wp\/v2\/categories?post=1339"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mudassirbackup.infinitycodestudio.com\/index.php\/wp-json\/wp\/v2\/tags?post=1339"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}