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
AnnyKZ [126]
2 years ago
9

Write a method that returns a version of the given array where all the 10's have been removed. The remaining elements should shi

ft left towards the start of the array as needed, and the empty spaces at the end of the array should be set to 0.
Ex: {1, 10, 10, 2} yields {1, 2, 0, 0}. You may modify and return the given array or make a new array.

Code:

public class RemoveTen {
public static void main(String[] args) {
int[] nums = {1, 10, 10, 2};
int[] result = removeTen(nums);
for(int i = 0; i < result.length; i++)
System.out.print(result[i] + " ");
}

public static int[] removeTen(int[] nums) {
/*FIXME Complete the implementation of the removeTen method*/
}
}
Computers and Technology
1 answer:
Harlamova29_29 [7]2 years ago
8 0

Answer:

The removeTens method is as follows

public static int[] removeTen(int[] nums) {

int [] arr = nums;

   int index = 0;

   while(index < arr.length && arr[index] != 10){

       index++;

   for(int j = index + 1; j < arr.length; j++) {

       if(arr[j] != 10) {

           arr[index] = arr[j];

           arr[j] = 10;

           index++;        }    }

   for( ; index < arr.length; index++){

       arr[index] = 0;}}

   return arr;

}

Explanation:

This defines the removeTens method; it receives array nums as its parameter

public static int[] removeTen(int[] nums) {

This creates and initializes a new array

int [] arr = nums;

This initializes index to 0

   int index = 0;

The following is repeated when array element is not 10 and if array index is still valid

   while(index < arr.length && arr[index] != 10){

This increments the index by 1

       index++;

This iterates through the array

   for(int j = index + 1; j < arr.length; j++) {

This checks if array element is not 10

       if(arr[j] != 10) {

If yes:

           arr[index] = arr[j];

The current array element is set to 10

           arr[j] = 10;

The index is incremented by 1        

  index++;        }    }

This iterates through the array again and move 0s to the back

   for( ; index < arr.length; index++){

       arr[index] = 0;}}

This returns the new array

  return arr;

}

You might be interested in
A manager wants to set up an area that is not on the LAN but not quite on the Internet. This area will house servers that will s
andreev551 [17]

Answer:

1. DMZ  (Demilitarized zone)

Explanation:

In computer networking, a Demilitarized Zone is a physical or logical network designed to give an extra layer of security on the organization’s private network. The DMZ acts as an interface between an untrusted network such as the internet and the organization’s internal network. When a server is set up in a demilitarized zone, users can reach it via its public IP address. In case there is an attack on the server, the private network is still protected.

3 0
2 years ago
What type of software testing is generally used in Software Maintenance?
zvonat [6]

Answer:

Regression Testing

Explanation:

6 0
2 years ago
What is the difference between a loop and a function?
Eduardwww [97]
Big difference
Loops allow you to execute code multiple times while a condition is true
Functions allow you to “call” a snippet of code whenever you want, and you can pass it arguments that could affect the data it returns
7 0
2 years ago
Read 2 more answers
Draw a flowchart or write pseudocode to represent a program's logic that allows the user to enter a value. The program multiplie
PIT_PIT [208]

Ill choose flowchart. Look picture for the answer

ask me if you have any doubts about my answer.

5 0
2 years ago
Question 6 (1 point)
Marysya12 [62]
<h2>answers</h2>

Extranet

wifi create extranet so that our mobile network runs smoothly. it can create lan,wan also

7 0
2 years ago
Other questions:
  • What is the purpose for the refresh button?
    10·2 answers
  • A program that interacts with another piece of software as it if were a human user is known as a(n) ________.
    5·1 answer
  • Which of the following statements about Linux is not​ true? A. Linux works on all the major hardware platforms. B. It plays a ma
    5·1 answer
  • Word's Help feature is useful if you need to quickly learn how to print a document
    14·1 answer
  • How to solve 3(x - 2) = 9x<br><img src="https://tex.z-dn.net/?f=3%28x%20-%202%29%20%3D%209x" id="TexFormula1" title="3(x - 2) =
    14·1 answer
  • Imagine that you have access to a class named MyCircle that has void setRadius(double r) and double getRadius() methods. Write a
    14·1 answer
  • Why, y did brainly just do that........or did it just happen to me
    12·2 answers
  • 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
  • Dynamics simulate stillness via calculations performed by the computer.
    13·2 answers
  • what extension of nat allows several hundred workstations to access the internet with a single public internet address
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!