Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Java help

Name: Anonymous 2011-10-17 0:03

Hey guys I need help with my java coding. I'm required to write a code that takes 3 numbers (user input) and sort them from smallest to largest. Can someone show me how to code this?

Name: Anonymous 2011-10-18 8:05


/**
 * This class sorts three numbers.
 * Standard Input: 3 integers separated by newline character.
 * Sample usage:
 *     java SortThreeNumbers.java
 *     1021
 *     377
 *     800
 */
public class SortThreeNumbers {
    public SortThreeNumbers(int a, int b, int c) {
        int x=(a<=b&&a<=c)?a:(b<=a&&b<=c)?b:c,y=(a>=b&&a>=c)?a:(b>=a&&b>=c)?b:c,z=(x!=a&&y!=a)?a:(x!=b&&y!=b)?b:c;
        System.out.println(x+" "+z+" "+y);
    }
    public static void main(String[] a) throws java.io.IOException {
        java.io.BufferedReader b = new java.io.BufferedReader(new java.io.InputStreamReader(System.in));
        new SortThreeNumbers(Integer.parseInt(b.readLine()),Integer.parseInt(b.readLine()),Integer.parseInt(b.readLine()));
    }
}

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List