StefanTobler

Lesson 34 Activity 4

Dec 8th, 2016
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.88 KB | None | 0 0
  1. /*
  2.  * Lesson 34 Coding Activity 4
  3.  *
  4.  * For the Lesson 34 activities, you will be asked to write one or more methods.
  5.  * Use the template to write a main method that tests each of your methods,
  6.  * then paste everything into the code runner box. Your submission should
  7.  * begin with the first import statement and end with the final }.
  8.  *  
  9.  * Write a method that takes an array of ints
  10.  * and returns the smallest value in the array.
  11.  *
  12.  *     public static int findMin(int [] a)
  13.  *
  14.  */
  15.  
  16.  
  17. import java.util.Scanner;
  18.  
  19. class Lesson_34_Activity_Four {
  20.  
  21.    public static int findMin(int [] a)
  22.     {
  23.     int min = 999999999;
  24.     for (int i = 0; i < a.length; i++)
  25.      {
  26.        if (a[i] < min)
  27.          min = a[i];
  28.      }
  29.      return min;
  30.     }
  31.  
  32.     public static void main(String[] args)
  33.      {
  34.      int a[] = {1,2,3};
  35.      System.out.println(findMin(a));
  36.     }
  37. }
Add Comment
Please, Sign In to add comment