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-17 16:26


import java.util.Scanner;

public class anus
{
    static Scanner s = new Scanner(System.in);
   
    public static void main(String args[])
    {
        int[] a = { getInt() },
              b = { getInt() },
              c = { getInt() };
        if(b[0] > a[0])
            swap(a,b);
        if(c[0] > a[0])
            if(c[0] > b[0]){
                swap(a,c);
                if(c[0] > b[0])
                    swap(b,c);
            }
            else
                swap(b,c);
        System.out.printf("[%d][%d][%d]%n",a[0],b[0],c[0]);
    }

    public static int getInt()
    {
        System.out.printf("Enter a integer: ");
        return s.nextInt();
    }
   
    public static void swap(int[] a,int[] b)
    {
        a[0] ^= b[0];
        b[0] ^= a[0];
        a[0] ^= b[0];
    }
}



ENTERPRISE QUALITY JAVA

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