StefanTobler

Lesson 34 Activity 3

Dec 8th, 2016
170
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 3
  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 and returns
  10.  * the largest value in the array.
  11.  *
  12.  *     public static int findMax(int [] a)
  13.  *
  14.  */
  15.  
  16.  
  17. import java.util.Scanner;
  18.  
  19. class Lesson_34_Activity_Three {
  20.  
  21.    public static int findMax(int [] a)
  22.     {
  23.      int max = 0;
  24.      for (int i = 0; i < a.length; i++)
  25.      {
  26.        if (a[i] > max)
  27.          max = a[i];
  28.      }
  29.      return max;
  30.     }
  31.  
  32.     public static void main(String[] args)
  33.      {
  34.      int a[] = {1,2,3};
  35.      System.out.println(findMax(a));
  36.     }
  37. }
Add Comment
Please, Sign In to add comment