您的位置:首页 > 编程语言 > Java开发

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

2016-09-13 11:27 543 查看
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);
}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: