shamus
06-03-2009, 05:38 PM
I am new to Java and I am trying to figure out how to complete this assignment. The assignment is as follows:
Write a program that prompts the user to input three numbers. The program should then output the numbers in ascending order. This is the code I have so far....
import java.util.*;
public class Chapter4 {
static Scanner console = new Scanner(System.in);
public static void main(String[] args)
{
int firstNum; //First number entered by user
int secondNum; //Second number entered by user
int thirdNum; //Third number entered by user
System.out.println("Enter a number: "); //input for first number entered by user
firstNum = console.nextInt();
System.out.println("Enter a number: "); //input for second number entered by user
secondNum = console.nextInt();
System.out.println("Enter a number: "); //input for third number entered by user
thirdNum = console.nextInt();
{
if ((firstNum <= secondNum) && (firstNum <= thirdNum))
System.out.println(firstNum);
else
if ((secondNum <= firstNum) && (secondNum <= thirdNum))
System.out.println(secondNum);
else
System.out.println(thirdNum);
}
}
}
What I can't seem to figure out is how to get the other numbers to display in ascending order. Any help would be great. If someone could point me in the right direction that would be wonderful.
Thank you :)
Write a program that prompts the user to input three numbers. The program should then output the numbers in ascending order. This is the code I have so far....
import java.util.*;
public class Chapter4 {
static Scanner console = new Scanner(System.in);
public static void main(String[] args)
{
int firstNum; //First number entered by user
int secondNum; //Second number entered by user
int thirdNum; //Third number entered by user
System.out.println("Enter a number: "); //input for first number entered by user
firstNum = console.nextInt();
System.out.println("Enter a number: "); //input for second number entered by user
secondNum = console.nextInt();
System.out.println("Enter a number: "); //input for third number entered by user
thirdNum = console.nextInt();
{
if ((firstNum <= secondNum) && (firstNum <= thirdNum))
System.out.println(firstNum);
else
if ((secondNum <= firstNum) && (secondNum <= thirdNum))
System.out.println(secondNum);
else
System.out.println(thirdNum);
}
}
}
What I can't seem to figure out is how to get the other numbers to display in ascending order. Any help would be great. If someone could point me in the right direction that would be wonderful.
Thank you :)