Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a method that accepts an integer array of unspecified length as a paramete

ID: 3620344 • Letter: W

Question

Write a method that accepts an integer array of unspecified length as a parameter. It should remove all negative values from the array and return the size of the altered array. Unused values at the end of the array should be filled with zeroes. For example, the array {3, 5, -2, 4, -3} should become {3, 5, 4, 0, 0} and 3 should be returned as the new length. Do not copy the array, modify the array that was passed as a parameter. What is the Big-O of this method? import java.io.*;
import java.util.*;

public class untitled2
{

public static void main(String args[])
{
//creating
int temp = 0;
int [] number = new int[5];
Scanner input = new Scanner(System.in);

System.out.println("Please enter numbers: ");
int j;
//first loop to
for (int i=0; i<number.length;i++)
{
number[i] = input.nextInt();
//System.out.print(number[i]);
}
System.out.println("Returned size of aray is " + shift(number));
for (int i=0; i<number.length;i++)
{
System.out.println(number[i]);

}
}
public static int shift(int []number)
{
int j=0;
int temp=0;
int k=0;
for (int i=0; i<number.length;i++)
{

if (number[i] < 0)
{
for (j=i; j < number.length-1;j++)
number[j]=number[j+1];
}
} } }


Write a method that accepts an integer array of unspecified length as a parameter. It should remove all negative values from the array and return the size of the altered array. Unused values at the end of the array should be filled with zeroes. For example, the array {3, 5, -2, 4, -3} should become {3, 5, 4, 0, 0} and 3 should be returned as the new length. Do not copy the array, modify the array that was passed as a parameter. What is the Big-O of this method? import java.io.*;
import java.util.*;

public class untitled2
{

public static void main(String args[])
{
//creating
int temp = 0;
int [] number = new int[5];
Scanner input = new Scanner(System.in);

System.out.println("Please enter numbers: ");
int j;
//first loop to
for (int i=0; i<number.length;i++)
{
number[i] = input.nextInt();
//System.out.print(number[i]);
}
System.out.println("Returned size of aray is " + shift(number));
for (int i=0; i<number.length;i++)
{
System.out.println(number[i]);

}
}
public static int shift(int []number)
{
int j=0;
int temp=0;
int k=0;
for (int i=0; i<number.length;i++)
{

if (number[i] < 0)
{
for (j=i; j < number.length-1;j++)
number[j]=number[j+1];
}
} } }


Write a method that accepts an integer array of unspecified length as a parameter. It should remove all negative values from the array and return the size of the altered array. Unused values at the end of the array should be filled with zeroes. For example, the array {3, 5, -2, 4, -3} should become {3, 5, 4, 0, 0} and 3 should be returned as the new length. Do not copy the array, modify the array that was passed as a parameter. What is the Big-O of this method? Write a method that accepts an integer array of unspecified length as a parameter. It should remove all negative values from the array and return the size of the altered array. Unused values at the end of the array should be filled with zeroes. For example, the array {3, 5, -2, 4, -3} should become {3, 5, 4, 0, 0} and 3 should be returned as the new length. Do not copy the array, modify the array that was passed as a parameter. What is the Big-O of this method? import java.io.*;
import java.util.*;

public class untitled2
{

public static void main(String args[])
{
//creating
int temp = 0;
int [] number = new int[5];
Scanner input = new Scanner(System.in);

System.out.println("Please enter numbers: ");
int j;
//first loop to
for (int i=0; i<number.length;i++)
{
number[i] = input.nextInt();
//System.out.print(number[i]);
}
System.out.println("Returned size of aray is " + shift(number));
for (int i=0; i<number.length;i++)
{
System.out.println(number[i]);

}
}
public static int shift(int []number)
{
int j=0;
int temp=0;
int k=0;
for (int i=0; i<number.length;i++)
{

if (number[i] < 0)
{
for (j=i; j < number.length-1;j++)
number[j]=number[j+1];
}
} } }

Explanation / Answer

   import java.io.*;
   import java.util.*;
   public class untitled
   {
      public static void main(String args[])
   {
      // creating
      int temp=0;
      int [] number = new int[5];
      int i;
      scanner input = new scanner(System.in);
      for(i=0;i<5;i++)
      {

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote