Advertisement
Guest User

Test

a guest
Apr 9th, 2020
246
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.22 KB | None | 0 0
  1. package com.company;
  2.  
  3. public class TestArray {
  4.  
  5.  
  6.     public static void main(String[] args) {
  7.  
  8.         int[] numArray = {3, 4, 9, 1, 7};
  9.  
  10.  
  11.         int maxValue= findMax(numArray);
  12.         System.out.println("Max Value is: " + maxValue);
  13.  
  14.         System.out.println("**********************************************");
  15.  
  16.         int minValue = findMax(numArray);
  17.         System.out.println("Min Value is: " + minValue);
  18.  
  19.  
  20.  
  21.     }
  22.  
  23.  
  24.  
  25.     static int minElement;
  26.     static int maxElement;
  27.  
  28.     public static int findMax(int[] numArray) {
  29.         for(int i=0; i<numArray.length; i++) {
  30.             for(int j=1; j<numArray.length; j++) {
  31.                 if(numArray[i] > numArray[j]) {
  32.                     maxElement = numArray[i];
  33.                     return maxElement;
  34.                 }
  35.             }
  36.         }
  37.         return -1;
  38.     }
  39.  
  40.  
  41.  
  42.  
  43.     public static int findMinMin(int[] numArray) {
  44.         for(int i=0; i<numArray.length; i++) {
  45.             for(int j=1; j<numArray.length; j++) {
  46.                 if(numArray[i] < numArray[j]) {
  47.                     minElement = numArray[i];
  48.                     return minElement;
  49.                 }
  50.             }
  51.         }
  52.         return -1;
  53.     }
  54.  
  55.  
  56.  
  57.  
  58.  
  59.  
  60.  
  61.  
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement