作者salami (史莱姆)
看板ZooStudy
标题计程作业第三题..
时间Mon Dec 1 14:56:14 2003
//hw3_3.java
import javax.swing.JOptionPane;
public class hw3_3{
public static void main(String args[]){
//input a,b,c and set temp
String input = JOptionPane.showInputDialog("Enter a double number for A : ");
double a = Double.parseDouble(input);
input = JOptionPane.showInputDialog("Enter a double number for B : ");
double b = Double.parseDouble(input);
input = JOptionPane.showInputDialog("Enter a double number for C : ");
double c = Double.parseDouble(input);
double t = 0.0;
//target a>b>c
System.out.println(a+" , "+b+" , "+c+" : step 0 = initial");
if(b>a){t = b; b = a; a = t;}
System.out.println(a+" , "+b+" , "+c+" : step 1 check");
if(c>a){t = c; c = b; b = a; a = t;}
System.out.println(a+" , "+b+" , "+c+" : step 2 check");
if(c>b){t = c; c = b; b = t;}
System.out.println(a+" , "+b+" , "+c+" : step 3 check = final");
//第三个step中 if(c>b),其实也可改成紧跟着step2 if(c>a)之後的else if(c>b)
//只是我为了逐步列出结果 多了很多麻烦 最後发现[第三步的else if]其实[直接改成if]也成立
//因为本题之中 [满足第二步条件者者 经过第二步的处理之後] [必定不满足第三步的条件]
//为了乾净一点 乾脆用if就好了 但是在逻辑上就要小心了
/*failure 这样写(不经过特别设计,直接两两交换)除非用回圈一直检查 直到条件完全满足才可以
if(b>a) {t=a;a=b;b=t;}
System.out.println(a+">"+b+">"+c+" step 1");
if(c>b) {t=b;b=c;c=t;}
System.out.println(a+">"+b+">"+c+" step 2");
if(c>a) {t=a;a=c;c=t;}
System.out.println(a+">"+b+">"+c+" step 3");
*/
//System.out.println(a+">"+b+">"+c);
//
System.exit(0);
}
}
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 140.112.7.59