Advertisement
Kendred

Minimum & Maximum

Mar 14th, 2019
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.82 KB | None | 0 0
  1. public class Program {
  2.  
  3. public static void main(String[] args) {
  4.  
  5. /*
  6. * Kendred Thompson
  7. * 4th Period
  8. * CS 2
  9. * Minimum & Maximum
  10. */
  11.  
  12. //Variables I changed the smallest to the largest
  13. int [] nums = {3, 1, 5, 3};
  14. int i, largest;
  15.  
  16. largest = nums[0];
  17. i = 1;
  18.  
  19. while(i < nums.length) {
  20.  
  21. //I changed the expression < to an > so it can read the largest variable in nums
  22. if(nums[i] > largest) {
  23.  
  24. largest = nums[i];
  25.  
  26. }
  27.  
  28. i = i + 1;
  29.  
  30. }
  31.  
  32. //prints the variable largest on the screen
  33. System.out.println(largest);
  34.  
  35. }
  36.  
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement