Compare the size of two numbers and customize the method of comparing the size of two integers

Source: Internet
Author: User

    • To compare the size of two numbers, customize the method of comparing the size of two integers:
    1. Returns 1 if the first number is large
    2. Returns 0 if equal
    3. If the first number is small, return-1
    • Enter a two number in the main () method to call this method
    • Example:

Please enter two number:

45

56

The second number is a large

Press any key to continue ...

1 usingSystem;2 usingSystem.Collections.Generic;3 usingSystem.Linq;4 usingSystem.Text;5 usingSystem.Threading.Tasks;6 7 namespacePaste8 {9     class ProgramTen     { One         Static voidMain (string[] args) A         { -Console.WriteLine ("Please enter a total of two integers:");//output Hint: Please enter two integers -             intA = Convert.ToInt32 (Console.ReadLine ());//accept input data and assign value to a the             intb = Convert.ToInt32 (Console.ReadLine ());//accept input data and assign value to B -             intresult = Test (A, b);//output A parameter to a method and return a value -             if(Result = =1)//if the return value is 1, the output string: The first number is large -             { +Console.WriteLine ("The first number is the big one"); -             } +             Else if(Result = =0)//output String If the return value is 0: two number equals A             { atConsole.WriteLine ("Two numbers equal"); -             } -             Else//the output string if the return value is not 1 or 0: The second number is large -             { -Console.WriteLine ("The second number is a large"); -             } inConsole.WriteLine ("Press any key to continue ...");//OUTPUT hint: Press any key to continue ... -Console.readkey ();//wait for the user to press any key to         } +         Static intTest (intAintb//a method for judging the size of two integers -         { the             if(A > B)//returns 1 if a is greater than B *             { $                 return 1;Panax Notoginseng             } -             Else if(A = = b)//returns 0 if a equals b the             { +                 return 0; A             } the             Else//If a is not less than b it is not equal to B 1 +             { -                 return-1; $             } $         } -     } -}

Compare the size of two numbers and customize the method of comparing the size of two integers

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.