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
defon
3 years ago
5

Complete the following method named replaceEvens that receives the parameter numbers which is an array of integers. The method m

ust replace all elements of numbers that store even values with the negative of that value. That is, if the number 12 is found in a given position of numbers, then the method must replace the 12 with a -12. You can assume that initially all values in the array are integers greater than zero.

Computers and Technology
1 answer:
Taya2010 [7]3 years ago
3 0

Answer:

Following are the method definition to this question:

public class Neg //defining class Neg

{  

public static void replaceEvens(int[] numbers) //defining a method replaceEvens that accepts array

{

int i; //defining integer variable

for(i = 0 ; i < numbers.length; i++) //defining foop to counts number

{

if(numbers[i]%2 == 0) //defining condition to check number is even  

{

numbers[i] = numbers[i] * -1; //multiply the number by -1

}

}

for(i = 0 ; i < numbers.length; i++) // defining loop print array

{

System.out.print(numbers[i] + " "); //print array

}

}    

public static void main(String[] as)//defining main method  

{

   int[] numbers = {12, 10, 18, 5, 2,22}; //defining array numbers and assign value

   System.out.println("Elements of array: "); //print message

   for(int i = 0 ; i < numbers.length ; i++)  //defining loop to print message

   {

   System.out.print(numbers[i] + " "); //print array

   }

  System.out.println("\n After replaceEvens"); //print message

   replaceEvens(numbers); //calling method replaceEvens

  }

}

Output:

please find the attachment.

Explanation:

  • In the given program a static method replaceEvens is declared, in which array numbers pass as the parameter, inside the for method loop is declared, which counts array number in this loop if block is defined, that check-in array there is an even number.
  • In the condition is true it will multiply the number by -1, and output side the loop it will define another loop to print its value.
  • Inside the main method, a number array is declared, that first prints its value then call the method to print its change value.    

You might be interested in
PLEASE ANYONE!!which present margins would be best to get the most information to fit on the page​
-Dominant- [34]

Answer:

Normal Margin is fit on the page. The default margins for Microsoft Word is normal margin.                                      

Explanation:

The paper visual effect give the document’s theme and quality. Margins send visual effects. Making a document right helps you to send the right message to readers. Use a small paper and adding a border.

You can change the page layout that people notice first with size, orientation, and margins.

Page margins make your document readable. Margins make the document more readable, make text look inviting, and given reviewers.

With narrower margins, you can reduce more words on-page.

To many words in a line make it difficult to read the document.

Margins are of many types

  • Normal Margin
  • Narrow margins
  • Moderate margins
  • Wide margins

Normal gives an equal inch to all sides of the page.

Narrow margins give little room to each column.

Average margins squeeze words from left and right.

Wide gives space when proofing the manuscript.

3 0
2 years ago
Read 2 more answers
What is adb command???​
Sedaia [141]

Answer:

<em>Android Debug Bridge (adb) is a versatile command-line tool that lets you communicate with a device. The adb command facilitates a variety of device actions, such as installing and debugging apps, and it provides access to a Unix shell that you can use to run a variety of commands on a device.</em>

Explanation:

<h3>I hope this helps!!</h3>
8 0
2 years ago
Read 2 more answers
What are the names of the components (each shown with a leader and a line) of a circuit shown in the diagram?
Goryan [66]

Answer:

The name of the components of the given labelled circuit is:

The box like figure in the given image is the battery source from where the current drawn into the circuit.

A string connecting positive terminal of battery to the bulb is an electric wire through which current flows in the circuit.

A bubble like object in the circuit is a bulb which lights up when current moves through the circuit.

A component connected to the negative terminal of batter source is a switch.

Then open circuit is an open as the key of the switch is open.

8 0
2 years ago
Analyze the following code.
denis-greek [22]

Answer:

C

Explanation:

No explanation, self-explanatory. I used class main instead...

4 0
3 years ago
There are two String variables, s1 and s2, that have already been declared and initialized. Write some code that exchanges their
Ivan

Answer:

//here is code in java.

import java.util.*;

class Solution

{

// main method of class

public static void main (String[] args) throws java.lang.Exception

{

   try{

    // declare an initialize first string variables

     String st1="hello";

     // declare an initialize first string variables

     String st2="world";

     // create another string variable

    String st3;

    // exchange the value of both string variables

    st3=st1;

    st1=st2;

    st2=st3;

    System.out.println("value of first String after exchange: "+st1);

    System.out.println("value of second String after exchange: "+st2);

   }catch(Exception ex){

       return;}

}

}

Explanation:

declare and initialize two string variables.Create another string variable "st3". first assign value of "st1" to "st3" after then value of "st2" to "st1" and then  assign value of "st3" to "st2". This will exchange the values of both the string.

Output:

value of first String after exchange: world

value of second String after exchange: hello

8 0
3 years ago
Read 2 more answers
Other questions:
  • Raeball was a lovin doll. And she spoke her mind as she stood tall. She made you special and loved. You're missed by so many. An
    10·2 answers
  • In modern computer memory, each location is normally composed of one byte.
    7·1 answer
  • After clicking the Start button on your computer screen desktop, what option would you then select to examine system components
    5·1 answer
  • Select the correct answer.
    10·2 answers
  • What is the FTC used car rule
    12·1 answer
  • 1) Using the density equation d=m/V: What is the density of a piece of metal with a mass o
    10·1 answer
  • Explain how the use of Git and a shared public Git repository simplifies the process of managing opensource development when man
    8·1 answer
  • If someone wanted to talk to a financial institution representative in person they would need to _____.
    5·1 answer
  • Any looping construct can be nested inside another loop is known as
    11·1 answer
  • Task 2: Typing a School Speech
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!