function and its invocation

Source: Internet
Author: User

classProgram { Public voidDayin () {Console.WriteLine ("Hollo World"); }        /// <summary>        ///Accumulate sum/// </summary>        /// <param name= "n" ></param>        /// <returns></returns>         Public intLeijia (intN) {intsum =0;  for(inti =1; I <= n;i++) {sum+=i; }            returnsum; }        /// <summary>        ///Enter a number to determine if it is prime/// </summary>        /// <param name= "n" ></param>        /// <returns></returns>         Public voidZhishu (intN) {intCount =0;  for(inti =1; I <= n;i++ )            {                if(n%i==0) {Count++; }            }            if(Count = =2) {Console.WriteLine ("Prime Number"); }            Else{Console.WriteLine ("not prime ."); }         }        /// <summary>        ///to find the factorial and its/// </summary>        /// <param name= "n" ></param>        /// <returns></returns>         Public voidJiecheng (intN) {intJiecheng =1; inthe =0;  for(inti =1; I <=n; i++) {Jiecheng*=i; He= he +Jiecheng; } Console.WriteLine ("Factorial is"+jiecheng+"Factorial and yes"+He); }        /// <summary>        ///scissors three innings and two wins/// </summary>        /// <param name= "a" ></param>        /// <param name= "B" ></param>         Public voidCaiquan () {intRenying =0; intDiannaoying =0;  for(inti =1; I <=3; i++) {Console.Write ("Please input people punch (0-scissors, 1-stone, 2-cloth) a="); intA =int.                Parse (Console.ReadLine ()); Random R=NewRandom (); intb = R.next (3); Console.WriteLine ("Computer Punch (0-scissors, 1-stone, 2-cloth) b="+b); if(A-B =1|| A-B =-2) {renying++; Console.WriteLine ("people win a game"); }                Else if(A = =b) {Console.WriteLine ("Draw"); I--; Continue; }                Else{diannaoying++; Console.WriteLine ("Computer wins a game"); }                if(Renying >=2) {Console.WriteLine ("three innings, two wins.");  Break; }                Else if(Diannaoying >=2) {Console.WriteLine ("three innings, two wins, computer wins .");  Break; }            }        }        //Main function        Static voidMain (string[] args) {             while(true)            {                NewProgram (). Dayin (); Console.WriteLine ("Please enter a positive integer"); intn =int.                Parse (Console.ReadLine ()); intJieguo =NewProgram (). Leijia (n);                Console.WriteLine (Jieguo); NewProgram (). Zhishu (n); NewProgram (). Jiecheng (n); NewProgram (). Caiquan ();            Console.ReadLine (); }        }    }

function and its invocation

Related Article

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.