How to access each digit in an int in Java
int n ; // some integer
while ( n > 0){
int digit = n % 10 ; //ones place digit
print(digit) ;
n = n / 10 ; // now the ones place by int division
}
How to access each digit in an int in Java
int n ; // some integer
while ( n > 0){
int digit = n % 10 ; //ones place digit
print(digit) ;
n = n / 10 ; // now the ones place by int division
}
ArrayFun3 – Please call your class that , exactly. Yes, you will lose a point for not following this simple specification.
int[] removeZeroes(int [] nums)
Description: This method returns a version of nums in which all occurrences of 0 , zero, are removed
| Method Call | return value/output |
| noZeroes( { 3 , 4, 0, 1} ) | { 3, 4, 1} |
| noZeroes( { 0, 5 , 0, 0, 9, 0, 1 , 11} ) | { 5,9,1,11} |
String[] removeNulls(String[] strs)
Description: This method returns a version of strsin which all null values are removed. Note:
int[] digitsToArray(int n)
@precondition n > 9
Description: This method takes each digit in the integer n and stores it in an array in reverse order, as shown below. First, make sure you understand the code here. , which btw, testers had to figure out , on the fly, in a previous AP A test.
int[] removeLeadingZeroes(int[] nums)
@precondition nums.length >=2
Description: This method returns an array in which all elements that meet the 2 criteria below are removed.
int[] doubleUp( int [] nums, int val)
@precondition nums.length >=2
Description: This method returns a version of nums –with all occurrences 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 codingbat