Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.javatechie.solution;
- import java.util.Arrays;
- public class ShiftAllZeroToEnd {
- public static void main(String[] args) {
- int[] array={4,32,0,1,0,5,0,7,8,9,0} ;
- int count=0;
- int len=array.length-1;
- for (int i:array){
- if(i!=0){
- array[count++]=i;
- }
- }
- while (count<len){
- array[count++]=0;
- }
- System.out.println(Arrays.toString(array));
- }
- }
Add Comment
Please, Sign In to add comment