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 Problem: Please answer both parts of the question fully: (a). Write Java code for a...
Java Problem: Please answer both parts of the question fully: (a). Write Java code for a method to test if a LinkedList<Long> has Long values that form a Fibonacci sequence from the beginning to the end and return true if it is and false otherwise. A sequence of values is Fibonnaci if every third value is equal to sum of the previous two. Eg., 3,4,7,11,18,29 is a Fibonacci sequence whereas 1,2,3,4 is not, because 2+3 is not equal to 4....
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...
3.) Analyze the Java Program LinkRotator RUN the code and add the screenshot of the window...
3.) Analyze the Java Program LinkRotator RUN the code and add the screenshot of the window and output. Describe what code change you would make if you wanted each link to be displayed for 2.5 seconds. _______________________________________________________________ Below is the "LinkRotator" java program: 1: package com.java24hours; 2: 3: import java.awt.*; 4: import java.awt.event.*; 5: import java.io.*; 6: import javax.swing.*; 7: import java.net.*; 8:    9: public class LinkRotator extends JFrame 10: implements Runnable, ActionListener { 11: 12: String[] pageTitle =...
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 CODE IN JAVA In this assignment you will write a program in that can figure...
PLEASE CODE IN JAVA In this assignment you will write a program in that can figure out a number chosen by a human user. The human user will think of a number between 1 and 100. The program will make guesses and the user will tell the program to guess higher or lower.                                                                   Requirements The purpose of the assignment is to practice writing functions. Although it would be possible to write the entire program in the main function, your...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT