1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
ivanzaharov [21]
3 years ago
8

Create a method called nicknames that passes an array as a parameter. Inside the method initialize it to hold 5 names of your ch

oice. Use the for each enhanced loop to print the elements of the array.
Computers and Technology
1 answer:
Gre4nikov [31]3 years ago
6 0
<h2>Answer:</h2>

    //======METHOD DECLARATION=========//          

    //method name: nicknames                                          

    //method return type: void                                            

    //method parameter: an array reference                    

    public static void nicknames(String [] names){      

       //initialize the array with 5 random names              

       names = new String[] {"John", "Doe", "Brian", "Loveth", "Chris"};

       //using an enhanced for loop, print out the elements in the array

       for(String n: names){

           System.out.print(n + " ");

       }

       

    }

<h2>Explanation:</h2>

The program is written in Java. It contains comments explaining important parts of the code. Kindly go through these comments.

A few things to note.

i. Since the method does not return any value, its return type is <em>void</em>

ii. The method is made public so that it can be accessible anywhere in and out of the class the uses it.

iii. The method is made static since it will most probably be called in the static main method (at least for testing in this case)

iv. The method receives an array of type <em>String </em>as parameter since the names to be stored are of type <em>String</em>.

v. The format of initializing an array manually should follow as shown on line 7. The <em>new</em> keyword followed by the array type (String), followed by the square brackets ([]) are all important.

vi. An enhanced for loop (lines 9 - 11) is a shorthand way of writing a for loop. The format is as follows;

=> The keyword <em>for</em>

=> followed by an opening parenthesis

=> followed by the type of each of the elements in the array. Type String in this case.

=> followed by a variable name. This holds an element per cycle of the loop.

=> followed by a column

=> followed by the array

=> followed by the closing parenthesis.

=> followed by a pair of curly parentheses serving as a block containing the  code to be executed in every cycle of the loop. In this case, the array elements, each held in turn by variable n, will be printed followed by a space.

A complete code and sample output for testing purposes are shown as follows:

==================================================

public class Tester{

    //The main method

    public static void main(String []args){

       

       String [] names = new String[5];

       nicknames(names);

    }

   

  //The nicknames method

    public static void nicknames(String [] names){

       names = new String[] {"John", "Doe", "Brian", "Loveth", "Chris"};

       for(String n: names){

           System.out.print(n + " ");

       }

       

    }

}

==================================================

<h2>Output:</h2>

John Doe Brian Loveth Chris

<em>NB: To run this program, copy the complete code, paste in an IDE or editor and save as Tester.java</em>

You might be interested in
For your biology class, you have taken a number of measurements for A plant growth experiment. you wish to create a chart that s
Natasha2012 [34]
The answer is B, calc or excel
4 0
3 years ago
Use comparison operators to write a question that the database will understand. Which records are more than or the same as three
Semmy [17]

Answer:

>=20

Explanation:

We are required to use the comparison operators, and they are like > , <, <=, >=, !=

We need to use more than or same:

And that is >=3000

And this is the required answer.

6 0
3 years ago
Which of the following is true of OEMs?
Alex73 [517]

Answer:  c. It does not include marketing in its value chain.

Explanation:

OEMs known in full as Original Equipment Manufacturers procure different components that they assemble  to make a final  product for their clients. Their clients include  re-sellers and distributors  who then  market  the products .In adding value to the products they also have research and development in order to come up with innovative products that are competitive within the market and offer solutions that meet the needs of their target market.

6 0
3 years ago
(blank) is an expansion card that enables a computer to connect to a network:
laiz [17]

Answer:

A

Explanation:

7 0
2 years ago
What information will you find in the 16-bit field in an IP datagram?
faust18 [17]

Answer: This 16-bit field defines the entire packet size in bytes, including header and data. The minimum size is 20 bytes (header without data) and the maximum is 65,535 bytes. All hosts are required to be able to reassemble datagrams of size up to 576 bytes, but most modern hosts handle much larger packets.

Explanation: Hopefully this helps you with what ever u are doing.

7 0
3 years ago
Other questions:
  • A news website uses 32-bit integers to count the number of times an article has been viewed. The website is becoming more popula
    10·1 answer
  • What are Three types of informational references
    9·2 answers
  • Transcoding digital videos does not cause a loss of quality. <br> a. True <br> b. False
    9·1 answer
  • Code
    7·1 answer
  • Items in the __________ area of a class are accessible to all entities that can "see" the object(s) of that class type
    10·1 answer
  • What are the three primary separation of concerns on the client-side of a dynamic web application? (Check all that apply)
    13·1 answer
  • Which options can be adjusted in the print settings?
    8·2 answers
  • What menu and grouping commands is the "SORT" tool? ( please answering meeeee)
    9·1 answer
  • Write an if-else statement that assigns 0 to the variable b if the variable a is less than 10. Otherwise, it should assign 99 to
    6·1 answer
  • To set up scenarios,then set up a list, then set up the reference cell. to set up the cells that display the output results from
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!