-->

2007年10月12日 星期五

Lab: Finding the max

Write a program to decide the max number of the three input number.
輸入三個變數,利用 if-else 方法,比較出哪個值為最大。
Ans:
import java.util.Scanner;

public class Findingmax
{
public static void main(String[] args)
{
Scanner keyboard = new Scanner(System.in);
double first, second, third;
System.out.println("Enter three numbers of nonnegative.");
first = keyboard.nextDouble( );
second = keyboard.nextDouble( );
third = keyboard.nextDouble( );
if ((first>=second)&&(first>=third))
System.out.println("Max number = " +first);
else if ((second>=first)&&(second>=third))
System.out.println("Max number = " +second);
else
System.out.println("Max number = " +third);
}

}

0 COMMENT: