C # exercise analysis after programming and development,

Source: Internet
Author: User

C # exercise analysis after programming and development,

C # Analysis of exercises after programming and development.

5.3 case 2

Use an array to store the scores of 10 students, calculate the total score and average score, and output

using System;?namespace boring{ ? ?class MainClass ?  {? ? ? ? ?public static void Main(string[] args) ? ? ?  { ? ? ? ? ? ?double sum = 0; ? ? ? ? ? ?double ave; ? ? ? ? ? ?int[] myArray = new int[10]; ? ? ? ? ? ?for (int i = 0; i != 10; i ++) { ? ? ? ? ? ? ? ?myArray[i] = int.Parse(Console.ReadLine()); ? ? ? ? ?  } ? ? ? ? ? ?for (int i = 0; i != 10; i++) { ? ? ? ? ? ? ? ?sum = sum + myArray[i]; ? ? ? ? ?  } ? ? ? ? ? ?ave = sum / 10; ? ? ? ? ? ?Console.WriteLine(sum); ? ? ? ? ? ?Console.WriteLine(ave); ? ? ?  }? ?  }}?
5.3 cases 3

Use ArrayList to store the scores of 10 students, add the total score of all students in the last item, delete the scores below 60, and output all the elements of ArrayList

using System;using System.Collections;?namespace Application{ ? ?class MainClass ?  { ? ? ? ?public static void Main(string[] args) ? ? ?  { ? ? ? ? ? ?double sum = 0; ? ? ? ? ? ?ArrayList arraylist = new ArrayList(11); ? ? ? ? ? ?for (int i = 0; i != 10; i++) { ? ? ? ? ? ? ? ?double t = int.Parse(Console.ReadLine()); ? ? ? ? ? ? ? ?arraylist.Add(t); ? ? ? ? ? ? ? ?sum = sum + t; ? ? ? ? ?  } ? ? ? ? ? ?arraylist.Add(sum); ? ? ? ? ? ?foreach(double p in arraylist) { ? ? ? ? ? ? ? ?if (p > 60) ? ? ? ? ? ? ? ?Console.Write(p + " ? "); ? ? ? ? ?  } ? ? ?  } ?  }}?
5.3 cases 4

Use Hashtable to store the scores of 10 students. Use name as the key and score as the value. Obtain the total score and add it to Hashtable.

using System;using System.Collections;?namespace Application{ ? ?class MainClass ?  { ? ? ? ?public static void Main(string[] args) ? ? ?  { ? ? ? ? ? ?double sum = 0; ? ? ? ? ? ?Hashtable tab = new Hashtable(11); ? ? ? ? ? ?for (int i = 0; i != 10; i++) { ? ? ? ? ? ? ? ?string y = Console.ReadLine(); ? ? ? ? ? ? ? ?int x = int.Parse(Console.ReadLine()); ? ? ? ? ? ? ? ?sum = sum + x; ? ? ? ? ? ? ? ?tab.Add(y, x); ? ? ? ? ?  } ? ? ? ? ? ?tab.Add("sum", sum); ? ? ? ? ? ?foreach (DictionaryEntry i in tab) { ? ? ? ? ? ? ? ?Console.WriteLine(i.Value); ? ? ? ? ?  } ? ? ?  } ?  }}?

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.