Please write in JAVA ONLY Write a program that uses an array

Please write in JAVA ONLY

Write a program that uses an array of integers initialized to whatever values you wish.

Write a methods to calculate and return the minimum and a method to calculate and return the maximum values in the array.

Write an additional method that accepts the array as a parameter and then creates and returns a new array with all the same values as the original plus 10.

Solution

ArrayMinMax.java

import java.util.Arrays;


public class ArrayMinMax {

   public static void main(String[] args) {
       int min = min(new int[]{1,2,3,4,5,6,7,8,9});
       int max = max(new int[]{1,2,3,4,5,6,7,8,9});
       int newArr[] = addTen(new int[]{1,2,3,4,5,6,7,8,9});
       System.out.println(\"Minimum Value is \"+min);
       System.out.println(\"Maximum Value is \"+max);
       System.out.println(\"New Array is \"+Arrays.toString(newArr));
   }
public static int min(int a[]){
       int min = a[0];
       for(int i=0; i<a.length; i++){
           if(min > a[i]){
               min = a[i];
           }
       }
       return min;
   }
  
   public static int max(int a[]){
       int max = a[0];
       for(int i=0; i<a.length; i++){
           if(max < a[i]){
               max = a[i];
           }
       }
       return max;
   }  
   public static int[] addTen(int a[]){
       int newArr[] = new int[a.length];
       for(int i=0; i<a.length; i++){
           newArr[i] = a[i] + 10;
       }
       return newArr;
   }
}

Output:

Minimum Value is 1
Maximum Value is 9
New Array is [11, 12, 13, 14, 15, 16, 17, 18, 19]

Please write in JAVA ONLY Write a program that uses an array of integers initialized to whatever values you wish. Write a methods to calculate and return the mi

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site