- Program must be written in C# You Do It Using the Sort) and ReverseO Methods I
ID: 3596932 • Letter: #
Question
- Program must be written in C#
You Do It Using the Sort) and ReverseO Methods In the next steps, you create an array of integers and use the SortO and ReverseO methods to manipulate it. 1. Open a new file and type the beginning of a program named ArrayDemo2 that includes an array of eight integer test scores, an integer you will use as a subscript, and a string that will hold user-entered data. using System; using static System.Console; class ArrayDemo2 static void MainO int[] scores = new int[8]; int x string inputString (continues)Explanation / Answer
using System.IO;
using System;
using static System.Console;
class ArrayDemo2
{
static void Main()
{
int [] scores = new int[8];
int x;
string inputString;
for(x=0;x<scores.Length;++x){
Write("Enter your score on test {0}", x+1);
inputString = ReadLine(); // read input string
scores[x] = Convert.ToInt32(inputString); // convert input to integer
}
WriteLine(" ---------------------------------");
WriteLine(" Scores in original order:");
for(x=0;x<scores.Length;++x){
Write("{0, 6}", scores[x]);
}
WriteLine(" ---------------------------------");
Array.Sort(scores); // sort array
WriteLine(" Scores in sorted order:");
for(x=0;x<scores.Length;++x){
Write("{0, 6}", scores[x]);
}
WriteLine(" ---------------------------------");
Array.Reverse(scores); // reverse array
for(x=0;x<scores.Length;++x){
Write("{0, 6}", scores[x]);
}
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.