a) Declare and instantiate an array named scores of twenty-five elements of type int. (b)Write a…
The following solution is suggested to handle the subject “a) Declare and instantiate an array named scores of twenty-five elements of type int. (b)Write a…“. Let’s keep an eye on the content below!
Question “a) Declare and instantiate an array named scores of twenty-five elements of type int. (b)Write a…”
Declare
and
instantiate an array named
scores of
twenty-five elements of type int.
(b)Write a statement
that
declares an
array namedstreetAddress
that contains
exactly eighty elements of typechar.
In a single
statement: declare, create and initialize
an
arraynamed
a of
ten
elements
of type
int
with the
values of
the elements (starting with the first) set
to 10, 20,..., 100
respectively.
Declare
an array
reference
variable,
week, and
initialize it to an array
containing the
strings “mon”, “tue“, “wed”, “thu“, “fri“, “sat”, “sun” (in that
order).
printArray is a method that accepts one
argument, an arrayof int.
The method prints the contents of the
array; it does not return a
value.
inventory is
an array of int
that has been
already declared and filled with
values. Write a
statementthat prints the contents of the
array
inventory by
calling the method printArray using a declared and
instantiated object named
obj.
Write the
definition of a method printArray, which has one
parameter, an array of int
.
The method
does not return a
value. The method prints out each element
of the
array, on a line by itself, in the
order the elements appear in the
array, and does not print anything
else.
Write a method
definition named makeString
that will accept a
variable parameter list of characters and return them as a single
string.
Declare a two
dimensional array named
ticTacToe with the appropriate type and
size.
Assign a default
value (any value you like based on the correct type you used in
question 8) to each element of the
ticTacToe array declared in question 8,
using a nested forloop.
Define a method
that accomplish question 8. The method is named fillInTwoDimArray, and returns nothing
but accepts a
two-dimensional array.
Change the values
of the following empty cells to
x’s
or o’s
(Does not matter
which) based
on your answer to question 7.
X | O | |
O | X | |
X | X |
Answer
Hi, I answered the first five questions.
Because you haven’t mentioned any programming languages, I answered in Java.
a) Declare an array of scores of twenty-five elements type int.
Ans: int [] scores = new int[25];
(b)Write an assertion declaring that the array streetAddress contains exactly eighty elements.
Ans: char[] streetAddress = char[8]
2. Declare, create, and initialize an array of ten elements type int. The values of the elements (beginning with the first) are set to 10, 20 100.
Ans: int[] a = new int[]10,20,30,40,50,60,70,80,90,100;
3. Create an array reference variable week and initialize it with the strings “mon”, ‘tue”, ‘wed”, thu”, ‘thu”, fri”, sat, and “sun”.
Ans: String[] week = “mon”, “tue”, “wed”, “thu”, “fri”, “sat”, “sun”;
4. printArray accepts only one argument, an arrayofint. This method prints the contents of an array, but does not return any value. Inventory is an array of int already declared and filled up with values. Use the declared and instantiated object obj to call the method printArray to print the contents of the inventory array.
Ans: obj.printArray(inventory);
You are welcome to repost other posts in a separate post.
Conclusion
Above is the solution for “a) Declare and instantiate an array named scores of twenty-five elements of type int. (b)Write a…“. We hope that you find a good answer and gain the knowledge about this topic of engineering.