代码:
import java.util.Scanner;
public class textch {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner reader=new Scanner(System.in);
System.out.println("请连续输入三个数,每输入一个,按回车键以确认:");
int x=reader.nextInt();
int y=reader.nextInt();
int z=reader.nextInt();
ch CH=new ch();
CH.exchange(x,y,z);
}
}
public class ch {
void exchange(int a,int b,int c)
{
int count=0;
int temp=0;
if(a>b)
{
temp=a;
a=b;
b=temp;
count++;
System.out.println("第"+count+"次交换的结果是"+a+","+b+","+c);
}
if(a>c)
{
temp=a;
a=c;
c=temp;
count++;
System.out.println("第"+count+"次交换的结果是"+a+","+b+","+c);
}
if(b>c)
{
temp=b;
b=c;
c=temp;
count++;
System.out.println("第"+count+"次交换的结果是"+a+","+b+","+c);
}
if(count==0)
System.out.println("第"+count+"次交换的结果是"+a+","+b+","+c);
}
}