Answers for "how to create array of values from a for loop"

0

arrays with for loops

// Find-Max
// Given a non-empty array of ints, returns
// the largest int value found in the array.
// (does not work with empty arrays)
public int findMax(int[] nums) {
  int maxSoFar = nums[0];  // use nums[0] as the max to start

  // Look at every element, starting at 1
  for (int i=1; i<nums.length; i++) {
    if (nums[i] > maxSoFar) {
      maxSoFar = nums[i];
    }
  }
  return maxSoFar;
}
Posted by: Guest on May-15-2020

Code answers related to "how to create array of values from a for loop"

Browse Popular Code Answers by Language