Ask Question

Create a program to determine the largest number out of 15 numbers entered (numbers entered one at a time). This should be done in a function using this prototype:

double larger (double x, double y);

+1
Answers (1)
  1. 19 February, 13:16
    0
    Output:-

    Enter number:

    2

    Enter number:

    1

    Enter number:

    4

    Enter number:

    3

    Enter number:

    5

    Enter number:

    7

    Enter number:

    6

    Enter number:

    8

    Enter number:

    9

    Enter number:

    11

    Enter number:

    10

    Enter number:

    12

    Enter number:

    14

    Enter number:

    13

    Enter number:

    15

    Largest number: 15.0

    Explanation:

    Below is a java program to determine the largest number out of 15 numbers entered: -

    import java. util. Scanner;

    public class Largest {

    double larger (double x, double y) {

    if (x>y)

    return x;

    else

    return y;

    }

    double findLargest () {

    double y;

    double greatest=0.0;

    Scanner s=new Scanner (System. in);

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

    System. out. println ("Enter number: ");

    y=s. nextDouble ();

    greatest=larger (greatest, y);

    }

    return greatest;

    }

    public static void main (String[] args) {

    Largest l=new Largest ();

    System. out. println ("Largest number: "+l. findLargest ());

    }

    }
Know the Answer?
Not Sure About the Answer?
Find an answer to your question 👍 “Create a program to determine the largest number out of 15 numbers entered (numbers entered one at a time). This should be done in a ...” in 📗 Computers & Technology if the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers