Question

create a new Java application called "MinMax" (without the quotation marks) that declares an array of...

create a new Java application called "MinMax" (without the quotation marks) that declares an array of doubles of length 5, and uses methods to populate the array with user input from the command line and to print out the max (highest) and min (lowest) values in the array.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Program Screenshots:

MinMax.java //create Application called MinMax public class MinMax //main method public static void main (String[] args) //cr//Implement method to find minimum and maximum array public static void findMaxMin (double[] arr) //declare variables doubleHow to Pass Command lines in Eclipse editor: * Right click on Java project » Click on Run Configurations: Pass the Command li

Code to be Copied:

MinMax.java

//Create Application called MinMax
public class MinMax
{
   //main method
   public static void main(String[] args)
   {
       //create an array of type double
       //length is 5
       double[] inputarray = new double[5];
       //call the method to pupulate array
       populateArray(args,inputarray);
       //call the method to find min and maximum in the array
       findMaxMin(inputarray);
   }

   //implement method to get the values
   //from the command line arguments
   private static void populateArray(String[] args,double[] inputarray)
   {
       System.out.println("Input Array is:");
       //Get the 5 arguments from command line
       //and store in the inputarray
       for(int i=0;i<args.length;i++)
       {
           //convert string to double
           inputarray[i]=Double.parseDouble(args[i]);
           //print the input arguments
           System.out.print(args[i]+" ");
       }
   }

   //Implement method to find minimum and maximum array
   public static void findMaxMin(double[] arr)
   {
       //declare variables
       double max, min;
       //set the starting value as min and max
       max = min = arr[0];
      
       //use for-loop to compare and compute the
       //min and max values in the array
       for(int i = 1; i < arr.length; i++)
       {
           if(arr[i] > max)
           {
               max = arr[i];
           }
           if(arr[i] < min)
           {
               min = arr[i];
           }
       }
       //print the minimum and maximum value
       System.out.println("\n\nHighest element in the given array is: "+ max);
       System.out.println("Lowest element in the given array is: "+ min);
   }
}

Add a comment
Know the answer?
Add Answer to:
create a new Java application called "MinMax" (without the quotation marks) that declares an array of...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • create a new Java application called "Scorer" (without the quotation marks) that declares a two-dimensional array...

    create a new Java application called "Scorer" (without the quotation marks) that declares a two-dimensional array of doubles (call it scores) with three rows and three columns and that uses methods and loops as follows. Use a method containing a nested while loop to get the nine (3 x 3) doubles from the user at the command line. Use a method containing a nested for loop to compute the average of the doubles in each row. Use a method to...

  • I've been assigned to create a new Java application called "CheckString" (without the quotation marks) according...

    I've been assigned to create a new Java application called "CheckString" (without the quotation marks) according to the following guidelines. ** Each method below, including main, should handle (catch) any Exceptions that are thrown. ** ** If an Exception is thrown and caught, print the Exception's message to the command line. ** Write a complete Java method called checkWord that takes a String parameter called word, returns nothing, and is declared to throw an Exception of type Exception. In the...

  • create a new Java application called "RecursiveTriangle" (without the quotation marks) according to the following guidelines....

    create a new Java application called "RecursiveTriangle" (without the quotation marks) according to the following guidelines. Modify the example in Horstmann Section 5.9, pp. 228-230 so that the triangle displays “in reverse order” as in the example below, which allows the user to set the number of lines to print and the String used for printing the triangle. Use a method to prompt the user for the number of lines (between 1 and 10) to print. This method should take...

  • create a new Java application called "CheckString" (without the quotation marks) according to the following guidelines....

    create a new Java application called "CheckString" (without the quotation marks) according to the following guidelines. ** Each method below, including main, should handle (catch) any Exceptions that are thrown. ** ** If an Exception is thrown and caught, print the Exception's message to the command line. ** Write a complete Java method called checkWord that takes a String parameter called word, returns nothing, and is declared to throw an Exception of type Exception. In the method, check if the...

  • create a new Java application called "WeightedAvgWithExceptions" (without the quotation marks), according to the following guidelines...

    create a new Java application called "WeightedAvgWithExceptions" (without the quotation marks), according to the following guidelines and using try-catch-finally blocks in your methods that read from a file and write to a file, as in the examples in the lesson notes for reading and writing text files. Input File The input file - which you need to create and prompt the user for the name of - should be called 'data.txt', and it should be created according to the instructions...

  • First, launch NetBeans and close any previous projects that may be open (at the top menu...

    First, launch NetBeans and close any previous projects that may be open (at the top menu go to File ==> Close All Projects). Then create a new Java application called "MultiDimensions" (without the quotation marks) that declares a two-dimensional array of doubles (call it scores) with three rows and three columns and that uses methods and loops as follows. Use a method containing a nested while loop to get the nine (3 x 3) doubles from the user at the...

  • create a new Java application called "WeightedAvgDataAnalyzer" (without the quotation marks), that modifies the DataAnalyzer.java in...

    create a new Java application called "WeightedAvgDataAnalyzer" (without the quotation marks), that modifies the DataAnalyzer.java in Horstmann Section 7.5, pp. 350-351 according to the specifications below. The input file should be called 'data.txt' and should be created according to the highlighted instructions below. Note that even though you know the name of the input file, you should not hard-code this name into your program. Instead, prompt the user for the name of the input file. The input file should contain...

  • Create a C program that: Within main, declares a linear array consisting of 10 double values....

    Create a C program that: Within main, declares a linear array consisting of 10 double values. You can assign values to the array when it is declared or fill them items manually using scanf () - your choice. Also, declare three doubles: min, max, and average. Then from within main, a function is called. The function should take a pointer to the array declared above and then finds the maximum value, the minimum value, and calculates the average of the...

  • Write a complete Java program called "AtmSimDoLoop" (without the quotation marks) according to the following specifications....

    Write a complete Java program called "AtmSimDoLoop" (without the quotation marks) according to the following specifications. It should use a do-while loop to prompt the user with the following starting prompt (without the horizontal lines) until the user enters 4 to quit. The program should start with an initial account balance, which you can set to any legitimate double value. Prompt the user with the following prompt (without the horizontal lines). Enter the number of your desired transaction type. Deposit...

  • Please write a Java program that does the following: Create an array of 100 integers. Store...

    Please write a Java program that does the following: Create an array of 100 integers. Store 100 random integers (between 1 and 100) in the array. Print out the elements of the array. Sort the array in ascending order. Print out the sorted array. Prompt the user to enter a number between 1 and 100. Search the array for that number and then display "Found" or "Not Found" message. Display each number from 1 to 100 and the number of...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT