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
Make sure to read all of these specifications carefully. Write a function, named array_shifter, that accepts an array of doubles
rosijanka [135]

Answer:

import java.util.Arrays;

public class num2 {

   public static void main(String[] args) {

//Create and initialize the first array        

double [ ]arr = {3.5, 5.6, 4.5, 6.7};

// Get the length of the array

       int n = arr.length;

      //Call the method Array Shifter inside the output statement

       System.out.println(Arrays.toString(array_shifter(arr,n)));

   }

   static double [] array_shifter(double [ ] doubleArray, int n){

       double [] narr = new double[n+1];

       //Loop through from index 1

       for(int i =0; i<narr.length-1; i++){

           narr[i] = doubleArray[i];

       }

       //Put a new element at the last index

       narr[narr.length-1] = 1.1;

       return narr;

   }

}

Explanation:

This is implemented in Java

Read detailed comments in the solution

The method array_shifter creates a new array that is one element larger than the array it received as argument and returns it

6 0
3 years ago
Which programming languages is best for game development? ​
kvasek [131]

Answer:

JavaScript. .

HTML 5.

SQL.

Python. .

Explanation:

hold it helps◕‿◕

3 0
2 years ago
Consider tree from the lectures on slide 10, write down the nodes in order as pro-
Leto [7]
The work same to be level order traverse and the sea is completely
7 0
3 years ago
Samantha is looking for a lens that is lightweight and small, making it easy to transport. She doesn’t care about the lens being
irina1246 [14]

Answer:

The correct option is;

d. Prime

Explanation:

A prime lens is a unifocal, or fixed-focal-length lens and it is referred to as the opposite of a zoom lens

The maximum aperture of ranges from f2.8 to f1.2, which are fast and have a creamy rendering of light that are out of focus, and also provide crispy image details, by making the most use of the light available and provide distinct combination of foreground and background images in pictures that give a crisp and visually pleasing appearance.

7 0
3 years ago
Read 2 more answers
The following is part of a log file taken from the machine on the network with the IP address of 192.168.1.106:__________.
Phantasy [73]

Answer:

Port scan targeting 192.168.1.106.

Explanation:

In the following question, there is some part of the question and options is missing.

In the following statement, when a file log is taken from the computer system which has Internet Protocol address is given in the statement and by the further details of the statement in which time and the port destination by examine those details of the Internet Protocol, the following port scan targeting the IP address 192.168.1.106.

3 0
3 years ago
Other questions:
  • 1.using synonyms can help make ur writing more________
    11·1 answer
  • A(n) _____ allows a user to choose specific files to back up, regardless of whether or not the files have been changed.
    9·1 answer
  • Fill in the blank
    11·1 answer
  • Instructions Write a program that asks the user for a number. If the number is between 1 and 255, the program outputs the corres
    15·1 answer
  • With an example in each, describe the use of two basic functions which are known by the "string.h" header file.
    6·1 answer
  • What is meant by check digit
    10·1 answer
  • True or False
    11·1 answer
  • Write a brief, two-page paper describing how your lifestyle and values impact your use of the Web for e-commerce. How is your on
    15·1 answer
  • Which option is referred to by the Reports Due tag?
    7·1 answer
  • What are the names of different types of tablets<br>​
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!