Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

move the zero elementts in array in java in tutorialspoint.dev

/* Java program to push zeroes to back of array */
import java.io.*; 
  
class PushZero 
{ 
    // Function which pushes all zeros to end of an array. 
    static void pushZerosToEnd(int arr[], int n) 
    { 
        int count = 0;  // Count of non-zero elements 
  
        // Traverse the array. If element encountered is 
        // non-zero, then replace the element at index 'count' 
        // with this element 
        for (int i = 0; i < n; i++) 
            if (arr[i] != 0) 
                arr[count++] = arr[i]; // here count is 
                                       // incremented 
  
        // Now all non-zero elements have been shifted to 
        // front and 'count' is set as index of first 0. 
        // Make all elements 0 from count to end. 
        while (count < n) 
            arr[count++] = 0; 
    } 
  
    /*Driver function to check for above functions*/
    public static void main (String[] args) 
    { 
        int arr[] = {1, 9, 8, 4, 0, 0, 2, 7, 0, 6, 0, 9}; 
        int n = arr.length; 
        pushZerosToEnd(arr, n); 
        System.out.println("Array after pushing zeros to the back: "); 
        for (int i=0; i<n; i++) 
            System.out.print(arr[i]+" "); 
    } 
} 
/* This code is contributed by Devesh Agrawal */
Comment

PREVIOUS NEXT
Code Example
Java :: capitalize in controlP5 
Java :: springboot endpoint body list 
Java :: activity show 1 time in android studio java 2022 
Java :: java domande risposta multipla 
Java :: hello world stack overflow 
Java :: ordenar mapa de forma descendente java 
Java :: detect view in scrollview android 
Java :: get material of block bukkit 
Java :: war file in java 
Java :: maximise the rides with the given tokens java 
Java :: forge close gui java 
Java :: open youtube by default in full screen pragmatically 
Java :: convert text file into binnary format bitmap using java 
Java :: android ussd code example 
Java :: newinstance in java giving exception 
Java :: data.sql not loading in springboot 
Java :: hashmap declare and initialize with values in 1 line java 
Java :: polymorphism vs overriding in java 
Java :: char to charsequence in java 
Java :: java listview 
Java :: mp3 player java 
Java :: Search a 2D Matrix II 
Java :: java format double no decimal places 
Java :: java 8 function supplier consumer 
Java :: ejercicios resueltos de python codeskulptor 
Java :: jbutton 
Sql :: oracle change nls_date_format permanently 
Sql :: remove mysql from centos 7 
Sql :: finding last created table mysql 
Sql :: sql list all databases 
ADD CONTENT
Topic
Content
Source link
Name
6+6 =