统计信息

  • 访问数:9422
  • 博客数:142
  • 建立时间:2008-01-05
  • 更新时间:2008-05-21
我叫王超然,是一名电脑爱好者,现在在新加坡留学上高一.我立志成为一名电脑人才,愿意在这里与大家一同分享我玩转电脑的心得.O-level华文考了A-One哈哈!

P5Q5

2008-04-08 13:23:38

天气: 晴朗 心情: 高兴

/*fileName:P5Q05.java
*Name:Wang Chaoran
* Description:
5 (Sorting three numbers)
Write the following method to display three numbers in increasing order:
public static void sort(double num1, double num2, double num3)
*/
import java.util.Scanner;
public class P5Q05{
  public static void main(String[] args)
  {
    //Input
    Scanner scan = new Scanner(System.in);
    System.out.println("Please enter the first number: ");
    double num1 = scan.nextDouble();
     System.out.println("Please enter the second number: ");
     double num2 = scan.nextDouble();
      System.out.println("Please enter the third number: ");
      double num3 = scan.nextDouble();
      //Output
      sort(num1, num2, num3);
  }
  //Method
  public static void sort(double num1, double num2, double num3){
    double temp =0;
    if(num1 >= num2){
      temp = num2;
      num2 = num1;
      num1 = temp;
    }
    temp =0;
    if(num1 >= num3){
       temp = num3;
      num3 = num1;
      num1 = temp;
    }
    temp =0;
    if(num2 >= num3){
       temp = num3;
      num3 = num2;
      num2 = temp;
    }
   
    System.out.println("Three numbers in increasing order: "+num1+", "+num2+", "+num3+".");
  }
}
    
     
加入收藏 编辑 审核

TAG: computing

我来说两句

OPEN

Powered by X-Space 1.2 © 2001-2006 Comsenz Technology Ltd