Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: javabat example makeLast

  1. #1
    Member Truffy's Avatar
    Join Date
    May 2009
    Location
    Philippines
    Posts
    93
    Thanks
    2
    Thanked 9 Times in 7 Posts

    Default javabat example makeLast

    Given an int array, return a new array with double the length where its last element is the same as the original array, and all the other elements are 0. The original array will be length 1 or more. Note: by default, a new int array contains all 0's.

    makeLast({4, 5, 6}) → {0, 0, 0, 0, 0, 6}
    makeLast({1, 2}) → {0, 0, 0, 2}
    makeLast({3}) → {0, 3}

    can anyone try this? i cannot get the end number. thanks.

    i cant make it.

    public int[] makeLast(int[] nums){
    int len = nums.length-1;
    int[] integerArray = new int[(nums.length * 2 -1) ]; 
     
    return  integerArray;
     
    }


    you can simulate it here:
    JavaBat Array-1 makeLast


  2. #2
    Member Truffy's Avatar
    Join Date
    May 2009
    Location
    Philippines
    Posts
    93
    Thanks
    2
    Thanked 9 Times in 7 Posts

    Default Re: javabat example makeLast

    Heres the answer.

    public int[] makeLast(int[] nums){
     int len = nums.length-1;
    int[] integerArray = new int[(nums.length * 2 ) ]; 
    integerArray[integerArray.length-1] = nums[nums.length-1];
    return  integerArray;
     
    }

  3. #3
    mmm.. coffee JavaPF's Avatar
    Join Date
    May 2008
    Location
    United Kingdom
    Posts
    3,336
    My Mood
    Mellow
    Thanks
    258
    Thanked 294 Times in 227 Posts
    Blog Entries
    4

    Default Re: javabat example makeLast

    Hello Truffy,

    Sorry I wasn't around to offer a solution. I'm glad you found the answer.
    Please use [highlight=Java] code [/highlight] tags when posting your code.
    Forum Tip: Add to peoples reputation by clicking the button on their useful posts.

  4. #4
    Member Truffy's Avatar
    Join Date
    May 2009
    Location
    Philippines
    Posts
    93
    Thanks
    2
    Thanked 9 Times in 7 Posts

    Default Re: javabat example makeLast

    Quote Originally Posted by JavaPF View Post
    Hello Truffy,

    Sorry I wasn't around to offer a solution. I'm glad you found the answer.
    Hi JavaPF,

    Good morning.

    Its okay. I know youre not around because the forum is quiet. But glad you're here again.

    Cheers,
    Truffy.