qq_34081024 于 2016.02.25 20:07 提问

import java.util.Scanner;

public class Work0225_8 {
public static void main(String[] args) {
// 输入三个double型的数据，放入到a,b,c三个变量中去
// 使用条件结构与交换逻辑将这三个变量中的值从小到大排列。
System.out.println("请您输入第一个double型数据 ：");
Scanner mySc = new Scanner(System.in);
double a = mySc.nextDouble();
System.out.println("请您输入第二个double型数据 ：");
double b = mySc.nextDouble();
System.out.println("请您输入第三个double型数据 ：");
double c = mySc.nextDouble();
// a 最大的情况
if ((a > b) && (a > c)) {
if (b > c) {
a = a + c;
c = a - c;
a = a - c;
System.out.println(a + "<" + b + "<" + c);
} else if (b < c) {
a = a + c;
c = a - c;
a = a - c;
a = a + b;
b = a - b;
a = a - b;
System.out.println(a + "<" + b + "<" + c);
}
}
// b 最大的情况
if ((b > a) && (b > c)) {
if (a > c) {
b = b + c;
c = b - c;
b = b - c;
a = a + b;
b = a - b;
a = a - b;
System.out.println(a + "<" + b + "<" + c);
} else if (a < c) {
b = b + c;
c = b - c;
b = b - c;
System.out.println(a + "<" + b + "<" + c);
}
}
// c 最大的情况
if ((c > a) && (c > b)) {
if (a > b) {
a = a + b;
b = a - b;
a = a - b;
System.out.println(a + "<" + b + "<" + c);
} else if (a < b) {
System.out.println(a + "<" + b + "<" + c);
}
}
}
}

7个回答

caozhy      2016.02.25 20:15

if ((a > b) && (a > c))

if ((c > a) && (c > b)) 此时a=1 b=2 c=3，所以又满足

caozhy      2016.02.25 20:17

qq_34081024 谢谢

wanghjbuf   2016.02.25 20:36

u013562148   2016.02.25 20:14

u013562148   2016.02.25 20:15

if ((a > b) && (a > c)) {
if (b > c) {
a = a + c;
c = a - c;
a = a - c;
System.out.println(a + "<" + b + "<" + c);
} else if (b < c) {
a = a + c;
c = a - c;
a = a - c;
a = a + b;
b = a - b;
a = a - b;
System.out.println(a + "<" + b + "<" + c);
}
}
// b 最大的情况
else _if ((b > a) && (b > c)) {
if (a > c) {
b = b + c;
c = b - c;
b = b - c;
a = a + b;
b = a - b;
a = a - b;
System.out.println(a + "<" + b + "<" + c);
} else if (a < c) {
b = b + c;
c = b - c;
b = b - c;
System.out.println(a + "<" + b + "<" + c);
}
}
// c 最大的情况
_else
if ((c > a) && (c > b)) {
if (a > b) {
a = a + b;
b = a - b;
a = a - b;
System.out.println(a + "<" + b + "<" + c);
} else if (a < b) {
System.out.println(a + "<" + b + "<" + c);
}
}
}
}

qq_34081024 回复qq_34081024: 这回对了，谢谢

qq_34081024 还是不对

qq_34081024   2016.02.25 20:15

enpterexpress   2016.02.25 20:10