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
Mark is learning to make logos. Once he finishes learning, he plans to freelance. Which software is most preferred to create art
MAVERICK [17]
Abode Illustrator helps to design logos in professional way
8 0
2 years ago
What is another name for “low-angle lighting”?
Sliva [168]
Another name for low-angle lighting is under-lighting.
4 0
3 years ago
What is the primary purpose of endnotes?
mihalych1998 [28]

Answer:

They acknowledge the source of a quotation, paraphrase, or summary; and (2) They provide explanatory comments that would interrupt the flow of the main text.so its B

5 0
2 years ago
Read 2 more answers
What type of maintenance can prevent the computer from breaking?
qwelly [4]
<span>The answer is, "Load anti-virus software".
</span>Anti-virus softwares are used to prevent computer from virus, as it name shows that are anti-virus means they prevent from virus. Anti virus softwares are also known as anti-malware software. These software work in such a way that they <span>prevent, detect and then remove viruses or </span><span>malicious software.</span>
3 0
3 years ago
Read 2 more answers
Terrence smiles at his customers, helps his coworkers, and stays late when needed. What personal skill does Terrence demonstrate
Salsk061 [2.6K]
Friendliness or it shows that he follows the rules
6 0
3 years ago
Read 2 more answers
Other questions:
  • you were discussing software privacy with a friend were surprised to learn how software privacy can impact your life everyday. w
    10·1 answer
  • Read the paragraph.
    12·2 answers
  • Need this!!
    11·2 answers
  • How to make changes to a file on the USB drive
    6·2 answers
  • What happens when you call someone whose phone is off?
    6·2 answers
  • p25: File Write and Read1) User enters a file name (such as "myMovies.txt").2) User enters the titles of 4 of their favorite mov
    12·1 answer
  • What is wrong with this code and correct it.
    12·1 answer
  • You're making great progress on your assignment. You've defined the purpose of your message, identified both the primary and sec
    9·1 answer
  • Is e commerce a challenge or opportunity to the freight forwarder
    8·1 answer
  • 16. A/An __________ is operated on the principle that the dying have special needs and wants that hospital personnel are too bus
    15·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!