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 CPU has just been powered on and it immediately executes a machine code instruction. What is the most likely type of instructi
adell [148]

The most likely type of instruction that was executed by the CPU is: a jump instruction.

<h3>What is a CPU?</h3>

A central processing unit (CPU) can be defined as the main components of a computer because it acts as the brain of a computer and does all the processing and logical control.

This ultimately implies that, a central processing unit (CPU) is typically used by a computer to execute an instruction or set of instructions when powered on.

<h3>What is a jump instruction?</h3>

In Computer technology, a jump instruction specifies an offset to a new place in the program sequence when processing an instruction or set of instructions in a computer.

Read more on CPU here: brainly.com/question/5430107

3 0
2 years ago
How do I center images in HTML. Also I need to have one image lay over another. How do I do this in HTML?
11111nata11111 [884]
HTML isn't really used for this anymore, it's  done via CSS (Cascading Style Sheets). On the web currently, HTML pretty much just describes what to be displayed, CSS describes how it's to be displayed and JavaScript is used to provide function to a web page.

In HTML, you could use: align="center" as an attribute of the img tag to center it. Now it's preferable to use text-align: center CSS for the object containing the image (a div or p).

Positioning things on top of each other brings in z-axis and position CSS. Check out the CSS tutorial at http://www.w3schools.com . It's free.
5 0
3 years ago
Write a recursive method called lengthOfLongestSubsequence(a, b) that calculates the length of the longest common subsequence (l
kompoz [17]

Answer:

Explanation:

The following code is written in Java and creates the recursive function to find the longest common substring as requested.

 static int lengthOfLongestSubsequence(String X, String Y) {

       int m = X.length();

       int n = Y.length();

       if (m == 0 || n == 0) {

           return 0;

       }

       if (X.charAt(m - 1) == Y.charAt(n - 1)) {

           return 1 + lengthOfLongestSubsequence(X, Y);

       } else {

           return Math.max(lengthOfLongestSubsequence(X, Y),

                   lengthOfLongestSubsequence(X, Y));

       }

   }

4 0
3 years ago
Which type of computer network ensures high security
Gwar [14]

Answer:

I elieve the answer for this is Juniper Network Firewall

Hope this helps

3 0
2 years ago
Timur was making a presentation regarding how attackers break passwords. His presentation demonstrated the attack technique that
kakasveta [241]

Answer:

The answer of the following question is Brute force attack .

Explanation:

A brute force attack is the error and trial method that is used by an application program to decode the encrypted data like passwords or the Data Encryption Standard (DES) keys, which through an exhaustive effort (by using brute force) rather than the employing an intellectual strategies.

7 0
2 years ago
Other questions:
  • Ryan has created a Word document to be used as a review quiz for students in a classroom setting. The document contains both que
    6·1 answer
  • 3. Of the following pieces of information in a document, for which would you most likely insert a mail merge field? A. First nam
    13·2 answers
  • A typist is entering text on keyboard at the rate of 30 words per minute. if each word is 6 characters long on average, what ban
    5·2 answers
  • (70 points) This is a legit question that I have for a device FOR my homework.
    5·2 answers
  • The convergence of information technology and operations technology, offering the potential for tremendous improvements in effic
    14·1 answer
  • Software is giving instructions so that text is displayed on the monitor. This software is an example of _____.
    7·2 answers
  • __________ is a very simple form of lossless data compression in which runs of data (that is, sequences in which the same data v
    6·1 answer
  • The best way to help prevent a system from a worm attack is to use anti-virus software anti-malware software a firewall a router
    12·1 answer
  • Please anyone, help me.... I'm not sure how to put these all together.<br> 35 points!
    15·2 answers
  • 5. What skill is unique to reading online?
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!