Judge the parity of an instance and the parity of an instance
Hide row number copy code? Judge the parity
// Determine whether the values are odd and even
import java.util.Scanner;
public class jsos {
public static void main(String[] args) {
System. out. print ("enter a number :");
Scanner i=new Scanner(System.in);
int num=i.nextInt();
if (num<=0) {
System. out. print ("enter a positive integer! ");
}else if (num%2==0) {
System. out. print ("" + num + "+" is an even number! ");
}else {
System. out. print ("" + num + "+" is an odd number! ");
}
}
}
Functions used to judge odd and even numbers in EXCEL
Input = IF (MOD (A1, 2) = 0, "even", "odd") in B1 ")
Meaning: divide the A1 value by 2 and take the remainder. If it is 0, true indicates that the even number is displayed. If it is 1, false indicates that the odd number is displayed.
How does asp determine the even and odd numbers?
Dim a, B
A = 10
B = false
If a mod 2 = 0 then
B = true
End if
In asp, mod is used to calculate the remainder,
A mod 2 means that the value of a is divided by 2 to calculate the remainder. If the remainder is 0, a can be divisible by 2, and the number that can be divisible by 2 is an even number. Otherwise, it is an odd number.