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
When you are given a set of tables and asked to create a database to store their data, the first step is to ________?
Vlad1618 [11]
Scan   the tables  to make a digital copy of them
6 0
3 years ago
You are building a network and need to connect five computers in an office. They will be on the same network segment and you sho
lilavasa [31]

Answer:

a lan party

Explanation:

because it's your personal party

4 0
3 years ago
What is x squared times b squared
Pie

Answer:

x^2 * b^2

Explanation:

Like 3 squared times 2 squared is 3*3*2*2. Similarly the expression given in the question is equal to x*x*b*b. And that explains what is mentioned in question.

3 0
3 years ago
When researching Information about technology for use in a project, it is NOT important to consider the date that the informatio
REY [17]

Answer:

B. False

Explanation:

Hope this helps!

4 0
1 year ago
3. What are two reasons for versioning your still life project file? (1.0 points)
inna [77]

Answer:

The project file can be managed by making its multiple version due to the following reasons.

1. We can create multiple copies or version of the project to avoid any unfortunate circumstance such as Project file can be corrupted or can be deleted. In that case we can use the other version of that project file.

2. When we are working on some project, we are modifying the code or program to achieve our desired results. In this process we may forgot the changes that we have made while modification. If we does not obtain our desired results while modification that can lead to losing the original file. To reduce this type of risk we create multiple versions of project File.

3. We also create version of our project files on some internet drives as a backup. In case our computer has lost or operating system has been corrupted. A version of our project file is available on Internet drives such as Google drive or Drop box.

3 0
3 years ago
Other questions:
  • Which occupation requires certification by the state?
    15·2 answers
  • You open the home page for www.alpineskihouse. On the home page, you see a link for the weather report. You want to view the wea
    6·1 answer
  • What are 2 plants that grow best in our soil type ​
    9·1 answer
  • Your task is to write and test a function which takes one argument (a year) and returns True if the year is a leap year, or Fals
    5·1 answer
  • Before measuring resistance of a component, be sure:
    8·1 answer
  • Assuming dataFile is an ofstream object associated with a disk file named payroll.dat, which of the following statements would w
    9·1 answer
  • Translate the following pseudocode for randomly permuting the characters in a string into a C++ program.
    15·1 answer
  • Why do we need to learn about engineering and technology?
    6·1 answer
  • Give an example of how loops are used in programming Kturtle​
    7·1 answer
  • Who was making the high-pitched growling noise that Francisco hears?
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!