Use n % 2 = 1 to determine whether it is an odd number:
Import Java. io. bufferedinputstream; import Java. util. extends; public class main {/*** @ Param ARGs */public static void main (string [] ARGs) {int A; using CIN = new using (New bufferedinputstream (system. in); While (CIN. hasnext () {A = cin. nextint (); system. out. println (isodd (a);}/*** determine whether a number is an odd number ** @ Param N * @ return */public static Boolean isodd (int n) {return n % 2 = 1 ;}}/* 2-2 3-3falsefalsetruefalse */
Use n % 2! = 0 to determine whether the integer is an odd number:
Import Java. io. bufferedinputstream; import Java. util. extends; public class main {/*** @ Param ARGs */public static void main (string [] ARGs) {int A; using CIN = new using (New bufferedinputstream (system. in); While (CIN. hasnext () {A = cin. nextint (); system. out. println (isodd (a);}/*** determine whether a number is an odd number ** @ Param N * @ return */public static Boolean isodd (int n) {return n % 2! = 0;}/** 2-2 3-3 False false true */
Use N & 1 = 1 to determine whether the integer is an odd number:
Import Java. io. bufferedinputstream; import Java. util. extends; public class main {/*** @ Param ARGs */public static void main (string [] ARGs) {int A; using CIN = new using (New bufferedinputstream (system. in); While (CIN. hasnext () {A = cin. nextint (); system. out. println (isodd (a);}/*** determine whether a number is an odd number ** @ Param N * @ return */public static Boolean isodd (int n) {return (N & 1) = 1 ;}/ ** 2-2 3-3 False false true */
To sum up, determine whether an integer is an odd number and use N % 2! = 0 and N & 1 = 1 are correct.
However, if an integer is an even number, it is correct to use N % 2 = 0 and N & 1 = 0.
Incorrect syntax:
Odd: N % 2 = 1
Even number: N % 2! = 1