2009年5月11日 星期一

Lab Finding the max of three numbers

Write a static method that computes the maximum of three float numbers.



------------------------------------------------<程式碼開始>--------------------------------------
import java.util.*;
import java.util.Scanner;
public class LabFindingmax {
public static float maximun(float n1, float n2, float n3) {
if(n1 > n2 && n1 > n3)
return n1;
else if(n2 > n1 && n2 > n3)
return n2;
else
return n3;
}
    public static void main (String args[]) {
Scanner Keyboard = new Scanner(System.in);
float a, b, c; 
System.out.println("Finding the max of three numbers\nNumber 1:");
a = Keyboard.nextFloat();
System.out.println("Number 2:");
b = Keyboard.nextFloat();
System.out.println("Number 3:");
c = Keyboard.nextFloat();
System.out.println("Max = " + maximun(a, b, c) );
    }
}


------------------------------------------------<程式碼結束>--------------------------------------
附註:手動輸入三個float數,找出最大值。

沒有留言:

張貼留言