簡體   English   中英

為什么不能將Math.max和Math.min添加或減去?

[英]Why is Math.max and Math.min not able to be added or subtracted to?

我試圖弄清楚為什么Math.max和Math.min無法正常工作。 我知道我可以使用,如果需要也可以使用陳述,但是有沒有其他方法可以使用?

    Scanner Scan = new Scanner(System.in);

    System.out.println("Enter three integers(Use enter in between): ");
    int x = Scan.nextInt();
    int y = Scan.nextInt();
    int z = Scan.nextInt();

    System.out.println(
      Math.min(x, Math.min(x, z))+", " // Prints the minimum of {x, z}
      +Math.max(x, Math.max(y, z))+", " // Prints the maximum of {x, y, z}
      +(
        Math.max(x, Math.max(y, z)) // Get the max of {x, y, z}
        +Math.min(x, Math.min(y, z)) // Get the min of {x, y, z}
        // Sum should be the sum of smallest and largest of {x, y, z}
      ) // Convert to string
      +(-x-y-z) // The sum of -1 * x+y+z, converted to String
    ); // println

一旦將Math.min(x, Math.min(x, z))更改為Math.min(x, Math.min(y, z)) ,對我來說似乎可以

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM