PDA

View Full Version : Java Program help


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 :)

shamus
06-03-2009, 06:52 PM
With help from a co-worker I was able to figure out how to write this out. I need to learn to take the assignment step by step. That really makes it a lot easier to understand.

Does anyone know of some websites that is good help for Java code?