Simple Java Help Required

Simple Java Help Required

Closed - This job posting has been filled and work has been completed.

Job Description

The Question I am answering is as follows;

Write a method with the following header to display three numbers in
increasing order:

public static void displaySortedNumbers(double num1, double num2, double num3)


Write a test program that prompts the user to enter three numbers and invokes
the method to display them in increasing order.

The code I have written is not displaying output correctly

I need someone to rectify my code and explain what was wrong;

import java.util.Scanner;

public class Q8 {

public static void main(String[] args) {



//Prompt the user to enter three numbers, in double

Scanner input = new Scanner(System.in);


System.out.print("Enter the first number: ");
double num1 = input.nextDouble();

System.out.print("Enter the second number: ");
double num2 = input.nextDouble();

System.out.print("Enter the third number: ");
double num3 = input.nextDouble();



//Display Unsorted Numbers

System.out.println("Given Numbers" + num1 + " " + num2 + " " + num3);
System.out.println("Displaying Sorted Numbers");

//Implement Calling Method to Display Sorted Numbers

displaySortedNumbers(num1,num2,num3);



}
public static void displaySortedNumbers(double num1, double num2, double num3)

{

if ((num1<num2) && (num1<num3))
System.out.print(num1 + " ");
{

if (num2<num3)
System.out.print(num2 + " " + num3);
else System.out.printf(num3 + " " + num2);
}
if ((num2<num1) && (num2<num3))

{
System.out.printf(num2 + " ");
if (num1<num3)
System.out.print(num1 + " " + num3);

else
System.out.print(num3 + " " + num1);
}

else

{ System.out.print(num3 + " ");

if(num1<num2)
System.out.print(num1 + " " + num2);

else
System.out.print(num2 + " " + num1);


}



}
}

Other open jobs by this client