C # ArrayList set-small example,

Source: Internet
Author: User

C # ArrayList set-small example,

You can use either of the following methods to compile a question: Enter the name, Chinese score, mathematical score, and English score to the set, find the total Chinese score, average mathematics score, the highest English score, and who is the highest English score.
Method 1: A collection
Console. Write ("Total number of inputs :");
Int s = int. Parse (Console. ReadLine ());
ArrayList ss = new ArrayList ();
For (int I = 0; I <s; I ++)
{
Console. Write ("no." + (I + 1) + "name :");
Ss. Add (Console. ReadLine ());
Console. Write ("no." + (I + 1) + "English score :");
Ss. Add (Console. ReadLine ());
Console. Write ("th" + (I + 1) + "Mathematical score :");
Ss. Add (Console. ReadLine ());
Console. Write ("no." + (I + 1) + "language score :");
Ss. Add (Console. ReadLine ());
}
For (int I = 1; I <= 4 * s; I + = 4)
{
For (int j = I; j <= 4 * s-4; j + = 4)
{
If (double. Parse (ss [I]. ToString () <double. Parse (ss [j + 4]. ToString ()))
{
Double ying = double. Parse (ss [I]. ToString ());
Ss [I] = ss [j + 4];
Ss [j + 4] = ying;
String xing = ss [I-1]. ToString ();
Ss [I-1] = ss [j + 3];
Ss [j + 3] = xing;
Double shu = double. Parse (ss [I + 1]. ToString ());
Ss [I + 1] = ss [j + 5];
Ss [j + 5] = shu;
Double yu = double. Parse (ss [I + 2]. ToString ());
Ss [I + 2] = ss [j + 6];
Ss [j + 6] = yu;
}
}
}
For (int I = 0; I <4 * s; I ++)
{
Console. WriteLine (ss [I]);
}
Double sum1 = 0;
Double sum2 = 0;
For (int I = 0; I <4 * s; I + = 4)
{
Sum1 + = double. Parse (ss [I + 2]. ToString ());
Sum2 + = double. Parse (ss [I + 3]. ToString ());
}
Console. WriteLine ("Total mathematical score:" + sum1 );
Console. WriteLine ("average Chinese score:" + (sum2/s ));
Console. WriteLine ("the person with the highest English score is:" + ss [0] + ", and the score is:" + ss [1]);
Console. ReadLine ();
Method 2: four collections
Console. Write ("Total number of inputs :");
Int s = int. Parse (Console. ReadLine ());
ArrayList ss = new ArrayList ();
ArrayList rr = new ArrayList ();
ArrayList tt = new ArrayList ();
ArrayList yy = new ArrayList ();
For (int I = 0; I <s; I ++)
{
Console. Write ("no." + (I + 1) + "name :");
Ss. Add (Console. ReadLine ());
Console. Write ("no." + (I + 1) + "English score :");
Rr. Add (Console. ReadLine ());
Console. Write ("th" + (I + 1) + "Mathematical score :");
Tt. Add (Console. ReadLine ());
Console. Write ("no." + (I + 1) + "language score :");
Yy. Add (Console. ReadLine ());
}
For (int I = 0; I <s; I ++)
{
For (int j = I; j <s-1; j ++)
{
If (double. Parse (rr [I]. ToString () <double. Parse (rr [j + 1]. ToString ()))
{
Double ying = double. Parse (rr [I]. ToString ());
Rr [I] = rr [j + 1];
Rr [j + 1] = ying;
String xing = ss [I]. ToString ();
Ss [I] = ss [j + 1];
Ss [j + 1] = xing;
Double shu = double. Parse (tt [I]. ToString ());
Tt [I] = tt [j + 1];
Tt [j + 1] = shu;
Double yu = double. Parse (yy [I]. ToString ());
Yy [I] = yy [j + 1];
Yy [j + 1] = yu;
}
}
}
For (int I = 0; I <s; I ++)
{
Console. WriteLine (ss [I] + "\ t ");
Console. WriteLine (rr [I] + "\ t ");
Console. WriteLine (tt [I] + "\ t ");
Console. WriteLine (yy [I] + "\ t ");
}
Double sum1 = 0;
Double sum2 = 0;
For (int I = 0; I <s; I ++)
{
Sum1 + = double. Parse (tt [I]. ToString ());
Sum2 + = double. Parse (yy [I]. ToString ());
}
Console. WriteLine ("Total mathematical score:" + sum1 );
Console. WriteLine ("average Chinese score:" + (sum2/s ));
Console. WriteLine ("the person with the highest English score is:" + ss [0] + ", score:" + rr [0]);
Console. ReadLine ();

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.