frontPiece

From ggc

Jump to: navigation, search

http://www.javabat.com/prob?id=Array1.frontPiece

public int[] frontPiece(int[] nums) {

 if nums=<1

{ return num[a; }

else if nums=>2 { return num[a,b]; }

return a; }



I don't know how to use an array to display a fraction of an array. Can I even use if statements?

Answer

Individual elements can be obtained from an array by using the array's name followed by the desired location:

nums[0]

for example is the first element in the array.

nums[1]

is the second element in the array. Consult our notes from class about how to create an array. Be sure that you know that an index exists prior to accessing it. For example, nums[1] does not exist if the array only has one element in it.





Views
Personal tools
Add to 
del.icio.usAdd to 
diggAdd to 
FacebookAdd to 
favoritesAdd to 
GoogleAdd to 
MySpaceAdd to 
PrintAdd to 
SlashdotAdd to 
StumbleUponAdd to 
Twitter