Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.company;
- public class TestArray {
- public static void main(String[] args) {
- int[] numArray = {3, 4, 9, 1, 7};
- int maxValue= findMax(numArray);
- System.out.println("Max Value is: " + maxValue);
- System.out.println("**********************************************");
- int minValue = findMax(numArray);
- System.out.println("Min Value is: " + minValue);
- }
- static int minElement;
- static int maxElement;
- public static int findMax(int[] numArray) {
- for(int i=0; i<numArray.length; i++) {
- for(int j=1; j<numArray.length; j++) {
- if(numArray[i] > numArray[j]) {
- maxElement = numArray[i];
- return maxElement;
- }
- }
- }
- return -1;
- }
- public static int findMinMin(int[] numArray) {
- for(int i=0; i<numArray.length; i++) {
- for(int j=1; j<numArray.length; j++) {
- if(numArray[i] < numArray[j]) {
- minElement = numArray[i];
- return minElement;
- }
- }
- }
- return -1;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement