Question
define a java funcrion that will recieve four numbers and print them out in decending order and return their average


44 23 57 30

57 44 30 23
2. Define a Java function that will receive four numbers and print them out in descending order and return their average. 44,
0 0
Add a comment Improve this question Transcribed image text
Answer #1
public static double printInOrder(int n1, int n2, int n3, int n4) {
    if (n1 <= n2 && n1 <= n3 && n1 <= n4) {
        Order3(n1, n2, n3, n4);
    } else if (n2 <= n1 && n2 <= n3 && n2 <= n4) {
        Order3(n2, n1, n3, n4);
    } else if (n3 <= n1 && n3 <= n2 && n3 <= n4) {
        Order3(n3, n1, n2, n4);
    } else {
        Order3(n4, n1, n2, n3);
    }
    return (n1 + n2 + n3 + n4) / 4.0;
}

public static void Order3(int n1, int n2, int n3, int n4) {
    int min;
    int max;
    int middle;
    min = n2;
    if (n3 < min) min = n3;
    if (n4 < min) min = n4;

    max = n2;
    if (n3 > max) max = n3;
    if (n4 > max) max = n4;

    middle = n2 + n3 + n4 - min - max;
    System.out.println(n1 + ", " + min + ", " + middle + ", " + max);
}
Add a comment
Know the answer?
Add Answer to:
define a java funcrion that will recieve four numbers and print them out in decending order...
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
  • •Write a java program to read 10 numbers and print them in reverse order. Modify your...

    •Write a java program to read 10 numbers and print them in reverse order. Modify your program to work for N numbers given by the user Extend your program to find the average of these numbers Extend your program to find the smallest number of these numbers Extend your program to find the largest number of these numbers •Write a program to read 10 numbers and print them in reverse order. Modify your program to work for N numbers given...

  • Write a Java program with a while statement that will only print out the numbers 50,...

    Write a Java program with a while statement that will only print out the numbers 50, 45, 40, 35, 30, 25.

  • 2. This function compares two numbers and returns them in increasing order. 1. Fill in the...

    2. This function compares two numbers and returns them in increasing order. 1. Fill in the blanks, so the print statement displays the result of the function call in order. 1 # This function compares two numbers and returns them 2 # in increasing order. 3 - def order_numbers(number1, number2): 4. if number2 > number1: return numberi, number2 6 else: return number2, number1 9 Run # 1) Fill in the blanks so the print statement displays the result # of...

  • IN JAVA 3 ZIPS, What Order?: Write a program named ZipOrder that the reads in three...

    IN JAVA 3 ZIPS, What Order?: Write a program named ZipOrder that the reads in three zip codes from standard input and prints to standard output one of three words: "ASCENDING", "DESCENDING", "UNSORTED". The zip codes are guaranteed to be distinct from each other. In particular: if each zip code read in is greater than to the previous one, "ASCENDING"  is printed. if each zip code read in is less than to the previous one, "DESCENDING" is printed. otherwise, "UNSORTED" is...

  • Write a JAVA code snippet which prints out numbers between 0 and 1,000,000, BUT only print...

    Write a JAVA code snippet which prints out numbers between 0 and 1,000,000, BUT only print the numbers which are a multiple of 3.

  • C++ Define a generic function called CheckOrder() that checks if four items are in ascending, neither,...

    C++ Define a generic function called CheckOrder() that checks if four items are in ascending, neither, or descending order. The function should return -1 if the items are in ascending order, 0 if the items are unordered, and 1 if the items are in descending order. The program reads four items from input and outputs if the items are ordered. The items can be different types, including integers, strings, characters, or doubles. Ex. If the input is: bat hat mat...

  • *MATLAB CODE* 3)Write a function 'mydsort' that sorts a vector in descending order (using a loop,...

    *MATLAB CODE* 3)Write a function 'mydsort' that sorts a vector in descending order (using a loop, not the built-in sort function). 4)write a function that will receive a vector and will return two index vectors: one for ascending order and one for descending order. Check the function by writing a script that will call the function and then use the index vectors to print the original vector in ascending and descending order. **Please make sure they work. I have found...

  • CONVERT CODE TO JAVA // A C++ program to Print all elements in sorted order from...

    CONVERT CODE TO JAVA // A C++ program to Print all elements in sorted order from row and // column wise sorted matrix #include<iostream> #include<climits> using namespace std;    #define INF INT_MAX #define N 4    // A utility function to youngify a Young Tableau. This is different // from standard youngify. It assumes that the value at mat[0][0] is // infinite. void youngify(int mat[][N], int i, int j) {     // Find the values at down and right sides of...

  • Python Help Please Problem 4-4: Make a list of 20 numbers and place them in a...

    Python Help Please Problem 4-4: Make a list of 20 numbers and place them in a random order (don't arrange them in ascending or descending order - make sure the list is truly random). Calculate and print out the largest number in the list and the lowest number in the list. Problem 4-5: Make a list of multiples of 5 between 1 and 100. Once you have your list, print it out. Problem 4-6: Generate a list of values from...

  • Java quiz need help :Add the following numbers in the order given to a (min) heap...

    Java quiz need help :Add the following numbers in the order given to a (min) heap using the heap add algorithm (with trickle-up). 23 - 57 - 12 - 85 - 72 - 55 - 8 - 49 - 88 - 62 - 11 - 94 Draw the generated heap (10 points) Then delete three elements from that heap using the heap remove algorithm and draw the resulting heap. (10 points)

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