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
Join my giggl PLEASE i am so bored link will be in comments
asambeis [7]

Answer:

in which app we had to join

5 0
2 years ago
Read 2 more answers
Ken is a table busser at a restaurant. Ken's boss has requested that instead of waiting to be told what tables need to be cleane
Vsevolod [243]
Ken can improve his initiative
5 0
3 years ago
Read 2 more answers
An alternative to hexadecimal notation for representing bit patterns is dotted decimal notation in which each byte
zysi [14]

An alternative to hexadecimal notation for representing bit patterns is dotted decimal notation in which each byte in the pattern is represented by its base ten equivalent. In turn, these byte representations are separated by periods. For example, 12.5 represents the pattern 0000110000000101 (the byte00001100 is represented by 12, and 00000101 is represented by 5), and the pattern 100010000001000000000111 is represented by 136.16.7. Represent each of the following bit patterns in dotted decimal notation,

a. 0000111100001111 b. 001100110000000010000000c. 0000101010100000

4 0
2 years ago
Write a method that prints on the screen a message stating whether 2 circles touch each other, do not touch each other or inters
beks73 [17]

Answer:

The method is as follows:

public static void checkIntersection(double x1, double y1, double r1, double x2, double y2, double r2){

    double d = Math.sqrt(Math.pow((x1 - x2),2) + Math.pow((y1 - y2),2));

    if(d == r1 + r2){

        System.out.print("The circles touch each other");     }

    else if(d > r1 + r2){

        System.out.print("The circles do not touch each other");     }

    else{

        System.out.print("The circles intersect");     }

}

Explanation:

This defines the method

public static void checkIntersection(double x1, double y1, double r1, double x2, double y2, double r2){

This calculate the distance

    double d = Math.sqrt(Math.pow((x1 - x2),2) + Math.pow((y1 - y2),2));

If the distance equals the sum of both radii, then the circles touch one another

<em>     if(d == r1 + r2){</em>

<em>         System.out.print("The circles touch each other");     }</em>

If the distance is greater than the sum of both radii, then the circles do not touch one another

<em>    else if(d > r1 + r2){</em>

<em>         System.out.print("The circles do not touch each other");     }</em>

If the distance is less than the sum of both radii, then the circles intersect

<em>    else{</em>

<em>         System.out.print("The circles intersect");     }</em>

}

6 0
2 years ago
Lisa and her husband would like to buy a house soon. She continuously pays bills late. How do her actions affect her and others?
stiks02 [169]
Well actually it affects her credit. Home owners would not want to sell a house to someone who doesn't pay bills on time. It shows he/she is unreliable

3 0
3 years ago
Read 2 more answers
Other questions:
  • You accidentally find someone's password and use it to get into a system. this is hacking.
    15·1 answer
  • What is an allocation unit?
    10·1 answer
  • Gina works in an SDLC team. When Gina makes changes to a file, no one else is allowed to acess it. Which type of version control
    10·1 answer
  • A 'array palindrome' is an array which, when its elements are reversed, remains the same (i.e., the elements of the array are sa
    6·1 answer
  • Convert the following four unsigned binary numbers to decimal and show your work:
    14·1 answer
  • Information is best described as
    10·1 answer
  • How to make a water bottle rocket??
    6·1 answer
  • Elizabeth works for a local restaurant at the end of her shift she read she’s required to write in the time that she arrived in
    14·1 answer
  • How do I add decimals in python?
    6·1 answer
  • What is the first thing animators need to determine when beginning a project?
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!