Question

QUESTION 1 Using the following declarations and a member of the Array class, int [ ]...

QUESTION 1

Using the following declarations and a member of the Array class,
int [ ] bArray = new int [10];
int location;
Using a method in the Array class, write a statement that would change the order of the elements in the bArray array. The contents of the first cell should hold what was in the last cell. The second cell should hold what was in the next to last cell.

__________________________

HINT: You must write the full statement which includes a call to a method in the Array class.

1 points   

QUESTION 2

Using the following declaration:
int [ ] anArray = {34, 55, 67, 89, 99};
WriteLine(anArray[1] + 100);
a call to the WriteLine( ) method would display ____________,

1 points   

QUESTION 3

Using the following declarations,
int counter = 0;  
double val;
double [ ] bArray = new double [10];
To display the contents of bArray, show what the foreach loop control construct would resemble.

______________

HINT: Write the first line of the loop - the line that has the foreach on it. You are not writing the body...just the loop control statement.

1 points   

QUESTION 4

Using the following declaration:
int [ ] anArray = {34, 55, 67, 89, 99};
WriteLine(anArray[2]);
a call to the WriteLine( ) method would display ____________,

1 points   

QUESTION 5

What is returned by the method named result shown below?
int result(int[ ] anArray, int num)
{
int i, r;
               for (r = 0, i = 1; i < num; ++i)
                              if (anArray[i] > anArray [r] )
r = i;
return (r);
}

the index of the largest of the first num elements of array anArray

the value of the largest of the first num elements of array anArray

the index of the smallest of the first num elements of array anArray

the value of the smallest of the first num elements of array anArray

the index of the last element greater than its predecessor within the first num elements of array anArray

1 points   

QUESTION 6

_____________ would create an array declaration to hold the names of five font strings. Use font as your identifier. HINT: Your declaration must be syntactically correct, complete with an ending semicolon.

1 points   

QUESTION 7

What is the effect of the following program segment?
int[ ] anArray = new int[50];
int i, j, temp;
string inValue;


for (i = 0; i < 50; ++i)
{
               Write("Enter Value");
               inValue = ReadLine( );
               anArray[i] = int.Parse(inValue);
}
temp = 0;

for (i = 1; i < 50; ++i)
  if (anArray[i] < anArray[0])
++temp;

arranges the elements of array anArray in ascending order

counts the number of elements of array anArray less than its initial element

reverses the numbers stored in the array

puts the largest value in the last array position

none of the above correct

1 points   

QUESTION 8

Using the following declaration:
int [ ] anArray = {34, 55, 67, 89, 99};
   WriteLine(anArray[anArray.Length − 2]);
a call to the WriteLine( ) method would display ____________,

1 points   

QUESTION 9

Assume you have a method heading that reads

public static void DoSomething (int [ ] temp)

A call to invoke the method sending in the array would look like:

______________________________________

HINT: Your declaration must be syntactically correct, complete with an ending semicolon.

1 points   

QUESTION 10

Using the following declaration:
int [ ] anArray = {34, 55, 67, 89, 99};
WriteLine(anArray[2 + 1] * anArray[0]);
a call to the WriteLine( ) method would display ____________,

1 points   

QUESTION 11

Using the following declaration:
int [ ] anArray = {34, 55, 67, 89, 99};
   WriteLine(anArray.Length);
a call to the WriteLine( ) method would display _____________.

1 points   

QUESTION 12

Using just the following declarations,
int counter = 0;  
int val;
int [ ] bArray = new int [10];
Write the body of the for loop that could be used to increment each element in bArray by 5. The for loop might loop like:

for (counter = 0; counter < bArray.Length; counter++)

__________________

HINT: You are not writing the control structure, just the body of the loop where counter will be the index used with the bArray.

1 points   

QUESTION 13

_____________ would create an array declaration and do a compile-time initialization to hold the 5 most common single character middle initials. The most common are A, N, R, S and T. Use middleInitial
as your identifier. HINT: Your declaration must be syntactically correct, complete with an ending semicolon.

1 points   

QUESTION 14

Using the following declarations and a member of the Array class,
int [ ] bArray = new int [10];
int location;
Using a method in the Array class, write a statement that would order the values in the bArray array in ascending order.

___________________

HINT: You must write the full statement which includes a call to a method in the Array class.

1 points   

QUESTION 15

Using the following declarations and a member of the Array class,
int [ ] bArray = new int [10];
int location;
Using a method of the Array class, write an assignment statement that would return the index in the bArray array where 14 is stored.

__________________________

HINT: You must write the full assignment statement which includes a call to a method in the Array class.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Solutions:

Solution 1:

Array.reverse(bArray);

reverse is a method in Array class which takes in the array and reverses it.

Solution 2:

Snippet will print 155 because the element in the anArray[1] is 55 hence 55 will get addition to 100 and final result will print on to the console i.e 155.

Solution 3:

foreach (int i in bArray)
{
    System.Console.Write("{0} ", i);
}

This wil print each element present in the bArray.

Solution 4:

The statement will print 67. Because the lement present in the anArray[2] is 67.

Solution 5:

the index of the largest of the first num elements of array anArray

Solution 6:

string[] font = new string[6];

Solution 7:

counts the number of elements of array anArray less than its initial element.

Solution 8:

This will print 89

anArray.Lenght will give out 5 (Length of the array) - 2 will result to 3 so anArray[3] is 89.

Solution 9:

DoSomething (anArray);

Solution 10:

This will print 3026

anArray[2 + 1] * anArray[0] lets simplify this

anArray[3] * anArray[0] //anArray[3] is 89 and anArray[0] is 34

89 * 34 = 3026

Solution 11:

This will rpint out 5. anArray.Length gives the length of the array.

Solution 12:

for(int i = 0; i<bArray.Length; i++){
            bArray[i] += 5;  
}

bArray[i] += 5; we can write it as bArray[i] = bArray[i] + 5;

we are adding 5 to that element and storing into the same index after adding it.

Solution 13:

char[] middleInitial = { 'A', 'N', 'R', 'S', 'T' };

Solution 14:

Array.Sort(bArray);

This will sort the array in ascending order.

Solution 15:

Array.IndexOf(bArray, 14);

This will return the index of the element present in the bArray.

Note: I hope I have made the things clear, if you find any issue then please doc omment below, If you liekd the solution then don't forget hit the like button.

Add a comment
Know the answer?
Add Answer to:
QUESTION 1 Using the following declarations and a member of the Array class, int [ ]...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • For the following C# program: Let’s add one more user defined method to the program. This...

    For the following C# program: Let’s add one more user defined method to the program. This method, called ReverseDump is to output the values in the array in revere order (please note that you are NOT to use the Array.Reverse method from the Array class). The approach is quite simple: your ReverseDump method will look very similar to the Dump method with the exception that the for loop will count backwards from num 1 to 0 . The method header...

  • Assume arr is an array of integers with the elements {30,15,30,17,5,15,8}. After using the following declarations...

    Assume arr is an array of integers with the elements {30,15,30,17,5,15,8}. After using the following declarations and the for-loop, give the order of elements in the resulting linked stack lst. int [ ] sArr2={30,15,30,17, 5, 15, 8}; int i=0; Linked Stack<Integer> lst=new LinkedStack<Integer>(); int fr=sArr2[0]; for(i = 1; i < 7; i++) if (fr < sArr2[i]) lst.push(fr); else fr=sArr2[i]; Options: A) 5,8,15,17 B) 5,5,15,15 C) 30,30,30,30 D) All of the Above

  • Which of the following are valid array declarations? a. int[] array- new int[10]; b. double [array...

    Which of the following are valid array declarations? a. int[] array- new int[10]; b. double [array double[10]; c. charl charArray "Computer Science"; None of the above Analyze the following code: class Test public static void main(Stringl] args) System.out.println(xMethod(10); public static int xMethod(int n) System.out.println("int"); return n; public static long xMethod(long n) System.out.,println("long"); return n The program displays int followed by 10 The program displays long followed by 10. The program does not compile. None of the above. tions 3-4 are...

  • AP computer science: please do not use other advanced ways to solve this problem, it is...

    AP computer science: please do not use other advanced ways to solve this problem, it is just an AP class in high school. Thank you so much! publie class ArrayMethods public class Array Methods // precondition: anArray is not null. target is an element in the array // postcondition: absolute value of difference between target and average of // precondition: anArray is not null // postcondition: anArray is output anArray is returned. public static void PrintArray (int [0 anArray) public...

  • Consider the following function bubbleSort. int bubbleSort(int num[], int numel) {       int i, j, temp,...

    Consider the following function bubbleSort. int bubbleSort(int num[], int numel) {       int i, j, temp, moves = 0;       for (i = 0; i < (numel - 1); i++)       {             for (j = 1; j < numel; j++)             {                   //missing code             }       } } A. Complete the missing code:- (4 Points) B. Assume that the array sort[] which has 8 elements, initially contains the values:- 22 5 67 98 45 32 101 99...

  • 3) [16 points total] Consider the following algorithm int SillyCalc (int n) int i; int Num, answer; if (n <=...

    3) [16 points total] Consider the following algorithm int SillyCalc (int n) int i; int Num, answer; if (n <= 4) return n 10; else { Num-SillyCalcl n/4) answer = Num + Num + 10; for (i-2; i<-n-1; ++) answer- answer+ answer; return answer; Do a worst case analysis of this algorithm, counting additions only (but not loop counter additions) as the basic operation counted, and assuming that n is a power of 2, i.e. that n- 2* for some...

  • Assume the following declarations have been made in main(): int howmany; Scanner kb = new Scanner(System.in);...

    Assume the following declarations have been made in main(): int howmany; Scanner kb = new Scanner(System.in); Random r = new Random(); Write code to do the following: Use a while loop to prompt the user for how many numbers are to be entered. If the user does not enter a positive number (a number greater than 0), display a message saying the number must be positive and to try again. Store this value in the howmany variable. Declare an integer...

  • An array of class objects is similar to an array of some other data type. To...

    An array of class objects is similar to an array of some other data type. To create an array of Points, we write Point parray [4]; To access the object at position i of the array, we write parray [i] and to call a method on that object method, we write parray [i]. methodName (arg1 , arg2 , ...) ; To initialize an array of objects whose values are known at compile time, we can write Point parray [4] =...

  • C# 1.)Using the following declaration: int [ , ] exampleArray = {{3, 5, 6, 7}, {2,...

    C# 1.)Using the following declaration: int [ , ] exampleArray = {{3, 5, 6, 7}, {2, 8, 9, 22}, {1, 0, 4, 11}}; ______________ would be displayed if the following output statement was executed. WriteLine(exampleArray.Rank); 2.)Using the following declaration: int [ , ] exampleArray = {{3, 5, 6, 7}, {2, 8, 9, 22}, {1, 0, 4, 11}}; ______________ would be displayed if the following output statement was executed. WriteLine(exampleArray[0, 2]); 3.) Using the following declaration: int [ , ] exampleArray...

  • Part I: Create a program class named TestArrays This class should have a main() method that...

    Part I: Create a program class named TestArrays This class should have a main() method that behaves as follows: Create an integer array of size 10. Using a loop, fill the elements with increments of 5, starting with 5 in the first element. Using the array elements, sum the second, fifth and seventh elements. Display the sum with a label. Change the fourth element to 86. Subtract 9 from the ninth element. Using a loop, display the elements of the...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT