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]
2 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]2 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
Pls help quick... will mark brainliest...
harina [27]

Answer:

the answer is c

Explanation:

6 0
3 years ago
Explain why testing can only detect the presence of errors, not their absence.
Alchen [17]

Explanation: Testing is a set of activities that aim to detect software anomalies in a way that the errors can be discovered and correctes. The goal of software testing is to observe if the software behavior meet the requirements that they are expected to meet. Testing demonstrates to the developer that the software fullfils its requirements and it is a way to find out if it behaves in a incorrect, undesirable ou different form from the specifications.

6 0
3 years ago
In the 1760s and early 1770s, the British government wanted to raise money by taxing the residents of its colonies in North Amer
Virty [35]

Answer: The Boston Tea party was when American colonists dumped tea into the Boston Harbor because they were mad at the British for taxing their tea.

Explanation: This started the Revolutionary War because it was the first big act of wanting a revolution from the American colonists.

4 0
2 years ago
You use worksheets to perform calculations. How do you perform these calculations?
Elena-2011 [213]
The main function you will use is.... Type SUM= in all caps into a cell and then you can control click cells to add them together. You can also add PEMDAS properties to do calculations withing it.
5 0
3 years ago
Read 2 more answers
I am confused about joins in sql.
WITCHER [35]

Answer:

eeee3eeeeeeeeeeeeeeeeeeee

5 0
3 years ago
Read 2 more answers
Other questions:
  • Jana keeps receiving friend requests from strangers on a social media site. This is making her uncomfortable.
    15·2 answers
  • What type of network is capable of delivering voice, video streams, text, and graphics between many different types of devices o
    15·1 answer
  • Which statement is true about the purpose of a work in process constraint?
    15·1 answer
  • Finding information on the Web is easy thanks to _____________, which provide on-screen menus, making navigation of the web as s
    11·1 answer
  • Because people can easily upload information and share online, they tend to:
    15·1 answer
  • Discuss briefly four types of websites and the criteria you will use to evaluate the content of a website
    8·1 answer
  • By convention only, either the first usable address or the last usable address in a network is assigned to the router (gateway)
    11·1 answer
  • Plzzz help i need this today :(
    15·1 answer
  • Select the correct answer.
    13·2 answers
  • You need to know more than just facts in order to use critical thinking skills.
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!