Go Back   Java Programming Forums > Java Standard Edition Programming Help > Collections and Generics

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 01-07-2009, 03:34 AM
Truffy's Avatar
Member
 

Join Date: May 2009
Location: Philippines
Posts: 86
Thanks: 2
Thanked 9 Times in 7 Posts
Truffy is on a distinguished road
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.

Java Code
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



Reply With Quote Share this thread on Facebook
Sponsored Links
  #2 (permalink)  
Old 01-07-2009, 03:58 AM
Truffy's Avatar
Member
 

Join Date: May 2009
Location: Philippines
Posts: 86
Thanks: 2
Thanked 9 Times in 7 Posts
Truffy is on a distinguished road
Default Re: javabat example makeLast

Heres the answer.

Java Code
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;

}
Reply With Quote
  #3 (permalink)  
Old 05-07-2009, 12:56 PM
JavaPF's Avatar
mmm.. coffee
 
5 Highscores

Join Date: May 2008
Location: United Kingdom
Posts: 1,210
Thanks: 60
Thanked 66 Times in 64 Posts
JavaPF is someone you want to know!JavaPF is someone you want to know!JavaPF is someone you want to know!

I'm feeling Inspired
Default Re: javabat example makeLast

Hello Truffy,

Sorry I wasn't around to offer a solution. I'm glad you found the answer.
__________________
Don't forget to add code tags around your code:

Forum Tip: Add to peoples reputation () by clicking the button on their useful posts.
Reply With Quote
  #4 (permalink)  
Old 06-07-2009, 01:25 AM
Truffy's Avatar
Member
 

Join Date: May 2009
Location: Philippines
Posts: 86
Thanks: 2
Thanked 9 Times in 7 Posts
Truffy is on a distinguished road
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.
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




100 most searched terms
Search Cloud
2 dimensional arraylist java 2d arraylist java actionlistener actionlistener in java actionlistener java actionlistener jbutton addactionlistener addactionlistener java avatar hardware id convert double to integer java double format java double to int java double to integer in java double to integer java eclipse shortcut keys eclipse tutorial for beginners exception in thread "awt-eventqueue-0" java.lang.outofmemoryerror: java heap space exception in thread "main" java.lang.outofmemoryerror: java heap space format double java get mouse position java hardware id avatar java 2 dimensional arraylist java 2d arraylist java actionlistener java addactionlistener java button actionlistener java convert double to int java double format java double to int java double to integer java for beginner eclippse java format double java forum java forums java get mouse position java ipod touch java list to map java mouse position java programming forum java programming forums java sendkeys java.lang.reflect.invocationtargetexception java.util.arraylist jbutton actionlistener jbutton java jtextarea font color programming forums string to int java two dimensional arraylist java writing apps for ipod touch

All times are GMT. The time now is 01:28 AM.
Powered by vBulletin® Copyright ©2000-2009, Jelsoft Enterprises Ltd.