Answers for "shifting array to the left by 4 cell"

0

shifting array to the left by 4 cell

public class LinearArray{
    public static void main(String [] args){
        int [] b = {10, 20, 30, 40, 50, 60};
        shiftLeft(b,4);
        printArray(b); // This Should Print: { 40, 50, 0, 0, 0, 0 }; 
    }

    public static void shiftLeft(int [] source, int k){
        for(int i=0,j=i+k;i<source.length-k;i++,j++){
            source[i]=source[j];
            source[j]=0;
        }
    }
}
Posted by: Guest on July-03-2021

Browse Popular Code Answers by Language