- To compare the size of two numbers, customize the method of comparing the size of two integers:
- Returns 1 if the first number is large
- Returns 0 if equal
- 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