集册 Java实例教程 使用三个double参数获得最大值。

使用三个double参数获得最大值。

欢马劈雪     最近更新时间:2020-01-02 10:19:05

875
使用三个double参数获得最大值。

import java.util.Scanner;


public class Main /**时代Java**/

{

   // obtain three floating-point values and determine maximum value

   public static void main(String[] args)

   {

      // create Scanner for input from command window

      Scanner input = new Scanner(System.in);


      // prompt for and input three floating-point values

      System.out.print(

         "Enter three floating-point values separated by spaces: ");

      double number1 = input.nextDouble(); // read first double

      double number2 = input.nextDouble(); // read second double

      double number3 = input.nextDouble(); // read third double


      // determine the maximum value

      double result = maximum(number1, number2, number3); 


      // display maximum value 

      System.out.println("Maximum is: " + result); /*from 时代Java公众号 - N o w J a  v a . c o m*/

   } 


   // returns the maximum of its three double parameters

   public static double maximum(double x, double y, double z)

   {

      double maximumValue = x; // assume x is the largest to start


      
展开阅读全文