(1) method to determine whether a number is the multiplication of 2: For the integer num, if (Num & (num-1) = 0, then this number is the multiplication of 2.
The procedure is as follows:
Public class test {
Public static void main (string [] ARGs ){
System. Out. println (issqure (512); // equivalent to test. issqure ()
}
Public static Boolean issqure (INT num) {// This method must use the static keyword, because we call this method directly in the main method, instead of calling through the class object, only static methods belong to the class itself, and can be called directly through the class without using the object
If (Num & (num-1) = 0 ){
Return true;
}
Else
Return false;
}
}
(2) determine whether a number is an odd number. If (Num % 2) = 0, the number is an odd number.
The procedure is as follows:
Public class test {
Public static void main (string [] ARGs ){
System. Out. println (test. isodd (513 ));
}
Public static Boolean isodd (INT num ){
If (Num % 2) = 0 ){
Return false;
}
Else
Return true;
}
}