Warming up
public void printFactors( int n )
Description: This method prints all factors of n
Method Call | return value/output |
printFactors( 5) | 1
5 |
printFactors( 6) | 1
2 3 6 |
printFactors( 9 ) | 1 3 9 |
printFactors( 15) | 1 3 5 15 |
public int[] getFactors( int n )
Description: This method returns an array populated with the factors on n
Method Call | return value/output |
getFactors( 5) | {1,5} |
getFactors( 6) | {1,2,3,6} |
getFactors( 9 ) | {1,3, 9} |
getFactors( 15) | {1,3,5} |
public int[] removeZeros(int [] nums)
Description: This method returns a version of the input –with all occurrences of 0 , zero, removed
Method Call | return value/output |
noZeros( { 3 , 4, 0, 1} ) | { 3, 4, 1} |
noZeros( { 0, 5 , 0, 0, 9, 0, 1 , 11} ) | { 5,9,1,11} |
** public int[] doubleUp( int [] nums, int val)
Description: This method retuns a version of the input –with all occurances of val duplicated.
Method Call | return value/output |
doubleUp( { 3 , 4, 0, 1} , 4 ) | { 3, 4 , 4, 0, 1} |
doubleUp( { 1, 3 , 1, 5 , 3, 3} , 3 ) | {1 , 3, 3 , 1, 5 , 3, 3, 3, 3 } |
Similar problems on codinbat
Pingback: Array Fun 2 [2021] - Mr. M online
Pingback: Array Fun 3 [Resizing] Version 2 - Mr. M online