第1个回答 2011-04-17
package com.zhidao.test;
public class OrderNum {
public void orderValue(int x, int y, int z) {
int a;
int b;
int c;
if (x > y && x > z) {
c = x;
if (y > z) {
a = z;
b = y;
} else {
a = y;
b = z;
}
} else if (x < y && x < z) {
a = x;
if (y > z) {
b = z;
c = y;
} else {
b = y;
c = z;
}
} else {
b = x;
if (y > z) {
a = z;
c = y;
} else {
a = y;
c = z;
}
}
System.out.println("a = "+a+"; b = "+b+"; c = "+c);
}
public static void main(String[] args)
{
OrderNum on=new OrderNum();
on.orderValue(1, 2, 3);
on.orderValue(3, 2, 1);
on.orderValue(1, 3, 2);
on.orderValue(2, 3, 1);
on.orderValue(2, 1, 3);
on.orderValue(3, 1, 2);
}
}
第2个回答 2011-04-17
public class Test {
public static void main(String args[]){
int a,b,c;
a=Integer.parseInt(args[0]);
b=Integer.parseInt(args[1]);
c=Integer.parseInt(args[2]);
int []result=new int[3];
if(a>=b){
if(a>=c){
result[0]=a;
if(b>=c){
result[1]=b;
result[2]=c;
}else{
result[1]=c;
result[2]=b;
}
}else{
result[0]=c;
result[1]=a;
result[2]=b;
}
}else {
if(c>=b){
result[0]=c;
result[1]=b;
result[2]=a;
}else{
result[0]=b;
if(a>=c){
result[1]=a;
result[2]=c;
}else{
result[1]=c;
result[2]=a;
}
}
}
a=result[2];
b=result[1];
c=result[0];
System.out.println(a);
System.out.println(b);
System.out.println(c);
}
}
第4个回答 2011-04-18
public static void sortInt(int a, int b, int c)
{
int temp = 0;
if (a > b)
{
temp = b;
b = a;
a = temp;
}
if (b > c)
{
temp = c;
c = b;
b = temp;
}
if (a > b)
{
temp = b;
b = a;
a = temp;
}
System.out.println(a + "-" + b + "-" + c);
}