Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I\'m in java one and i\'m sctuck with this program. please can sombody help me?

ID: 3676235 • Letter: I

Question

I'm in java one and i'm sctuck with this program. please can sombody help me? please follow the directions.thank you.(answers as soon as posible)

Programming Concepts

1. Arrays
2. forloops

Exercise Location

For this exercise, you will copy a program from my directory into yours. It doesn't matter what directory this exercise is located in. You will need to copy this command and paste it into Loki:

cp ~lkoperski/1404_Lab/Exercises/Exercise08.java .

Exercise Description

You will initialize an array with the numbers 5, 29, -16, 50, and 0. After that, you will print the array and calculate the min/max, and print that out.

Exercise Requirements

1. When printing out the array, make sure to print out each number, followed by a comma and a space.

output example

user@loki:~$ java Exercise08

Here is the array: [5, 29, -16, 50, 0]

Min: -16
Max: 50

Explanation / Answer


/**
* The java Exercise08 that prints array elements
* and finds min and maximum element in the array
* and print to console.
* */
//Exercise08.java
public class Exercise08
{
   public static void main(String[] args)
   {

       //an array of integer values
       int arr[]={5, 29, -16, 50,0};
       System.out.println("Here is the array:");
       //call print method that prints the elments
       print(arr);

       //call findMin
       int min=findMin(arr);
       System.out.println("Min:"+min);
       //call findMax
       int max=findMax(arr);
       System.out.println("Max:"+max);
   }

  
   //Method findMax that takes integer
   //and returns maximum vlaue
   private static int findMax(int[] arr) {
       //Assume that element at =0 is max
       int max=arr[0];
      
       for (int i = 1; i < arr.length; i++) {
           if(arr[i]>max)
               max=arr[i];
       }
       //retunr max
       return max;
   }

   //Method findMin that takes integer
       //and returns minimum vlaue
   private static int findMin(int[] arr) {
       //Assume that element at =0 is min
       int min=arr[0];
      
       for (int i = 1; i < arr.length; i++) {
           if(arr[i]<min)
               min=arr[i];
       }
       //return min
       return min;
   }

   /**The method print that takes integer arrray
   * and prints the elements in the array*/
   private static void print(int[] arr) {      
       System.out.printf("[%d,",arr[0]);
       int index;
       for (index = 1; index < arr.length-1; index++) {
           System.out.printf("%d,",arr[index]);
       }
       System.out.printf("%d] ",arr[index]);
   }
}


------------------------------------------------------------------------------------------------------------------------------------------------

Sample output:

Here is the array:
[5,29,-16,50,0]
Min:-16
Max:50

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote