Java第三章40页例3-1(对整数排序)

来源:互联网 发布:mssql server 2008 r2 编辑:程序博客网 时间:2024/06/06 10:00

Number  类

/* * To change this template, choose Tools | Templates * and open the template in the editor. *//** * * @author Administrator */public class Number {    public void sort(int a,int b,int c){        int count=0;        int temp=0;        if(a>b){            temp=a;            a=b;            b=temp;            count=count+1;            System.out.println("the count is "+count+" and the result is "+a+" "+b+" "+c);        }        if(a>c){            temp=a;            a=c;            c=temp;            count=count+1;            System.out.println("the count is "+count+" and the result is "+a+" "+b+" "+c);                    }        if(b>c){            temp=b;            b=c;            c=temp;            count=count+1;            System.out.println("the count is "+count+" and the result is "+a+" "+b+" "+c);                          }        if(count==0){            System.out.println("the count is "+count+" and the result is "+a+" "+b+" "+c);                    }    }}

Test 类

/* * To change this template, choose Tools | Templates * and open the template in the editor. *//** * * @author Administrator */public class Test {    public static void main(String[] args){       // int a,b,c;      //  Input ip=new Input();      //  a=ip.scan();        Number num=new Number();        num.sort(88, 77,22);    }    }


0 0
原创粉丝点击