Problem 47

2 comments on “Problem 47”


  • Yogesh

    Solution from Yogesh Jadhav([email protected]):
    Under while loop by mistake k is k-; This not k- but correct as k–;

    public class ArrayShift
    {
    public static void main(String[] args) {
    int k=2;
    int ct=-1;
    int index=0;
    int a[]=new int[]{3,4,5};
    int b[]=new int[a.length];
    while(k>=1){
    for(int i=0;i<a.length;i++){
    ct++;
    if(i==a.length-1){
    b[index]=a[i];
    index++;
    }
    }
    for(int j=0;j<ct;j++){
    b[index]=a[j];
    index++;
    }
    for(int c=0;c<a.length;c++){
    a[c]=b[c];
    }
    k–;
    ct=-1;
    index=0;
    }
    for(int m=0;m<a.length;m++){
    System.out.print(a[m]);
    }
    }
    }


  • Yogesh

    Solution from Yogesh Jadhav([email protected]):
    public class ArrayShift
    {
    public static void main(String[] args) {
    int k=2;
    int ct=-1;
    int index=0;
    int a[]=new int[]{3,4,5};
    int b[]=new int[a.length];
    while(k>=1){
    for(int i=0;i<a.length;i++){
    ct++;
    if(i==a.length-1){
    b[index]=a[i];
    index++;
    }
    }
    for(int j=0;j<ct;j++){
    b[index]=a[j];
    index++;
    }
    for(int c=0;c<a.length;c++){
    a[c]=b[c];
    }
    k–;
    ct=-1;
    index=0;
    }
    for(int m=0;m<a.length;m++){
    System.out.print(a[m]);
    }
    }
    }