Selected Java API's
Reverse
To reverse an array: Array name "nums", Method "zeroFront"
public int[] zeroFront(int[] nums) { int left = 0; int right = nums.length-1; while ( left < right ) { int temp = nums[left]; nums[left] = nums[right]; nums[right] = temp; left++; right--; } return nums; }
Printing an Array
Using Method "printArray"
import java.util.Arrays; // class and main method header goes here System.out.print(main(printArray));
Timing your Array
In milliseconds:
Put in your main method:
long start = System.currentTimeMillis(); System.out.print(System.currentTimeMillis() - start);
insert the code here
Sorting Array
Before the main method:
import java.util.arrays;
In the main method:
Arrays.sort( nums );
More to come…
More to come…