. NET Study notes----2015-07-08 (Basic review and Exercise 05)

Source: Internet
Author: User

1, using the method to achieve: There is a string array: {" Malone ", " Michael Jordan ", " Reggie Miller ", " Timdenken ", " Kobe Bryant "}, Please output the longest string.

        Static voidMain (string[] args) {            string[] STRs = {"Malone","Michael Jordan","Reggie Miller","Timdenken","Kobe Bryant" }; Console.WriteLine ("The longest string is: {0}", Exportstr (STRs));        Console.readkey (); }        /// <summary>        ///determine the longest element in a string array/// </summary>        /// <param name= "STRs" >array of strings to judge</param>        /// <returns>returns the longest string</returns>        Static stringEXPORTSTR (params string[] STRs) {            stringMaxstr ="";  for(inti =0; I < STRs. Length; i++)            {                if(Strs[i]. Length >Maxstr. Length) {Maxstr=Strs[i]; }            }            returnMaxstr; }

2, using the method to achieve: Please calculate the average of an integer array. {1, 3, 5, 7, 93, 33, 4, 4, 6, 8, 10}. Requirement: Calculates the result if there are decimals, then two digits (rounded) after the decimal point are displayed.

        Static voidMain (string[] args) {            int[] arr = {1,3,5,7, the, -,4,4,6,8,Ten }; //saves the output to 2 decimal places. Console.WriteLine (Math.Round (AVG (arr),2));        Console.readkey (); }        /// <summary>        ///calculates the average of an integer array/// </summary>        /// <param name= "arr" >array of integers to be computed</param>        /// <returns>returns the average of a double type</returns>        Static DoubleAVG (params int[] arr) {            DoubleAVG =0.00; Doublesum =0.00;  for(inti =0; I < arr. Length; i++) {sum+=Arr[i]; } avg= SUM/arr.            Length; returnavg; }

. NET Study notes----2015-07-08 (Basic review and Exercise 05)

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.