Write in Java. Given an array A, push all the zeros of the array to the front. The order of all other elements should remain same. Write a function: void pushZero(int[] A) that accepts an integer array A. The function should convert the original array as per above requirement. Input: 10 2 0 3 4 0 4 0 10 9 0 where, First line represents size of an array N. Second line represents array elements. There must be single space between each element. There should be one space after the last element. Output: 0 0 0 0 2 3 4 4 10 9 There must be single space between each element of output array. There should be one space after the last element. N is an integer within the range [1 to 1,000,000]. - Starter Code: import java.util.*; import java.lang.*; import java.io.*; class HW2_P3{ public int[] getArray() { Scanner scanner = new Scanner(System.in); //Write code here to get array and return it } public void pushZero(int array[]) { //Write code here to push zero to front } } class DriverMain { public static void main(String args[]) { HW2_P3 hw = new HW2_P3(); int[] array = hw.getArray(); hw.pushZero(array); for(int i=0; i
Write in Java.
Given an array A, push all the zeros of the array to the front. The order of all other elements should remain same.
Write a function:
void pushZero(int[] A)
that accepts an integer array A. The function should convert the original array as per above requirement.
Input:
10
2 0 3 4 0 4 0 10 9 0
where,
- First line represents size of an array N.
- Second line represents array elements. There must be single space between each element.
- There should be one space after the last element.
Output:
0 0 0 0 2 3 4 4 10 9
- There must be single space between each element of output array.
- There should be one space after the last element.
- N is an integer within the range [1 to 1,000,000].
- Starter Code:
import java.util.*;
import java.lang.*;
import java.io.*;
class HW2_P3{
public int[] getArray() {
Scanner scanner = new Scanner(System.in);
//Write code here to get array and return it
}
public void pushZero(int array[]) {
//Write code here to push zero to front
}
}
class DriverMain {
public static void main(String args[]) {
HW2_P3 hw = new HW2_P3();
int[] array = hw.getArray();
hw.pushZero(array);
for(int i=0; i<array.length; i++) {
System.out.print(array[i]+" ");
}
}
}
Trending now
This is a popular solution!
Step by step
Solved in 3 steps