Question

In: Computer Science

Please show screenshot outputs and fully functional code for the Java program. Write the following methods...

Please show screenshot outputs and fully functional code for the Java program.

Write the following methods to  

1) read the content of an array of 5 doubles

public static double[] readingArray()

2) find and print:the smallest element in an array of 5 double

public static void smallest(double [] array)

3) find and print:the largest element in an array of 5 doubles

pubic static void largest (double [] array)

In the main method

- invoke readingArray and enter the following numbers 50 20 10 40 30

- invoke smallest

- invoke largest.

Solutions

Expert Solution

Java code:

import java.util.*;

public class Abc

{   //This function will read the Array

    public static double[] readingArray()

    {   

        Scanner sc = new Scanner(System.in);

        double array[] = new double[5];

        System.out.print("Please enter array elements: ");

        for(int i=0;i<5;i++){

            array[i] = sc.nextDouble();

        }

        return array;

    }

   //This function will take array and display smallest element.

    public static void smallest(double [] array){

        //Initialize min with first element of array.  

        double min = array[0];  

        for (int i = 0; i < array.length; i++) {  

            //Compare elements of array with min  

           if(array[i] < min){  

               min = array[i];

           }

        }

        System.out.println("Smallest element in given array is: " + min);   

    }

    //This function will take array and display largest element.

    public static void largest (double [] array){

        //Initialize max with first element of array.  

        double max = array[0];  

        for (int i = 0; i < array.length; i++) {  

            //Compare elements of array with max  

           if(array[i] > max){  

              max = array[i];

           }

        }

        System.out.println("Largest element in given array is: " + max);   

    }

    // main() method

    public static void main(String[] args)

    {

        // initializing double array

        double[] array;   

        array = readingArray();   //called readingArray method  

        smallest(array); //Calling the smallest method with 1 parameter.

        largest(array); //Calling the largest method with 1 parameter.

    }

}

OUTPUT:


Related Solutions

Please show fully functioning Java code and screenshots of outputs. Please separate by 1a and 1b....
Please show fully functioning Java code and screenshots of outputs. Please separate by 1a and 1b. #1. Design a Java JProduct class for a product which implements both cloneable and comparable interfaces The class should have the following private member variables: m_id: an integer that holds the product ID m_name: a string that holds the product name m_wholesaleprice: a double that holds the wholesale price m_retailers: a String array that holds all retailers who sell the product and the class...
JAVA CODE FOR BEGINNERS!! DON'T USE FOR OR WHILE METHODS PLEASE! Write a program that reads...
JAVA CODE FOR BEGINNERS!! DON'T USE FOR OR WHILE METHODS PLEASE! Write a program that reads three strings from the keyboard. Although the strings are in no particular order, display the string that would be second if they were arranged lexicographically.
Please write a java program that has the following methods in it: (preferably in order)   a...
Please write a java program that has the following methods in it: (preferably in order)   a method to read in the name of a University and pass it back a method to read in the number of students enrolled and pass it back a method to calculate the tuition as 20000 times the number of students and pass it back a method print the name of the University, the number of students enrolled, and the total tuition Design Notes: The...
Java please! Write the code in Exercise.java to meet the following problem statement: Write a program...
Java please! Write the code in Exercise.java to meet the following problem statement: Write a program that will print the number of words, characters, and letters read as input. It is guaranteed that each input will consist of at least one line, and the program should stop reading input when either the end of the file is reached or a blank line of input is provided. Words are assumed to be any non-empty blocks of text separated by spaces, and...
Write a Java program for RSA encryption that has the following inputs and outputs: Given a...
Write a Java program for RSA encryption that has the following inputs and outputs: Given a message and an integer n = pq where p and q are odd primes and an integer e > 1 relatively prime to (p − 1)(q − 1), encrypt the message using the RSA cryptosystem with key (n, e).
Please write the code JAVA Write a program that allows the user to enter the last...
Please write the code JAVA Write a program that allows the user to enter the last names of five candidates in a local election and the number of votes received by each candidate. The program should then output each candidate’s name, the number of votes received, and the percentage of the total votes received by the candidate. Your program should also output the winner of the election. A sample output is: Candidate      Votes Received                                % of Total Votes...
This question is about java program. Please show the output and the detail code and comment...
This question is about java program. Please show the output and the detail code and comment of the each question and each Class and interface. And the output (the test mthod )must be all the true! Thank you! Question1 Create a class Animal with the following UML specification: +-----------------------+ | Animal | +-----------------------+ | - name: String | +-----------------------+ | + Animal(String name) | | + getName(): String | | + getLegs(): int | | + canFly(): boolean | |...
Please write a java code. Write a generic program for New Home Construction Pricing with the...
Please write a java code. Write a generic program for New Home Construction Pricing with the following specifications. Note, each one of the 2, 3 or 4 bedroom homes are priced with standard type bathrooms. Update to deluxe or premium choice of bathrooms can be ordered by paying the difference in prices.    Types of homes Price 2 bedroom, 2 bathroom (standard type) and 1 car garage home = $350,000 3 bedroom, 2 bathroom (standard type) and 2 car garage...
Methods – Compute Grade Please write a complete Java program, given the following information about (a...
Methods – Compute Grade Please write a complete Java program, given the following information about (a few lines of code in) main: projectAverage = getAverage(”Project”); // returns average of 2 grades testAverage = getAverage(”Test”); // returns average of 2 grades displayGrade(projectAverage, testAverage); // test are 70% & projects 30%
Please complete both questions in MASM. Explain code clearly, thank you. Please screenshot memory outputs. Symbolic...
Please complete both questions in MASM. Explain code clearly, thank you. Please screenshot memory outputs. Symbolic Text Constants Write a program that defines symbolic names for several string literals (characters between quotes). Use each symbolic name in a variable definition. Use this code to get started: ; Symbolic Text Constants Comment ! Description: Write a program that defines symbolic names for several string literals (characters between quotes). Use each symbolic name in a variable definition. ! .386 .model flat,stdcall .stack...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT