我叫王超然,是一名电脑爱好者,现在在新加坡留学上高一.我立志成为一名电脑人才,愿意在这里与大家一同分享我玩转电脑的心得.O-level华文考了A-One哈哈!
天气: 晴朗
心情: 高兴
/*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+".");
}
}
导入论坛查看(26)回复(0)引用(0)好评(0) 差评(0)
加入收藏
编辑
审核
TAG:
computing