Judge the parity of an instance and the parity of an instance

Source: Internet
Author: User

Judge the parity of an instance and the parity of an instance

 

 

Hide row number copy code? Judge the parity
  1. // Determine whether the values are odd and even
  2. import java.util.Scanner;
  3. public class jsos {
  4.     public static void main(String[] args) {
  5. System. out. print ("enter a number :");
  6.         Scanner i=new Scanner(System.in);
  7.         int    num=i.nextInt();
  8.         if (num<=0) {
  9. System. out. print ("enter a positive integer! ");
  10.         }else if (num%2==0) {
  11. System. out. print ("" + num + "+" is an even number! ");
  12.         }else {
  13. System. out. print ("" + num + "+" is an odd number! ");
  14.         }
  15.     }
  16. }

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.