- import java.util.*;
- public class TQC205 {
- /**
- * @param args
- */
- public static void main(String[] args) {
- System.out.println("輸入兩個數字 x 和 y ,以逗號分隔:");
- Scanner s = new Scanner(System.in);
- String g = s.nextLine();
- float y=0,x=0 ;
- String[] sa = g.split(",");
- try
- {
- x = Float.valueOf(sa[0]);
- y = Float.valueOf(sa[1]);
-
- }catch(Exception e)
- {
- System.out.println("輸入參數不正確");
- System.exit(0);
- }
- System.out.println("x="+x);
- System.out.println("y="+y);
- System.out.println("大於或等於 x 的最大整數為: "+Math.floor(x));
- System.out.println("小於或等於 x 的最大整數為: "+Math.ceil(x));
- /* /////////////// /////////////////////*/
- System.out.println("最接近 x 的整數為: "+Math.rint(x));
- System.out.println("x四捨五入值為: "+Math.round(x));
- /*///////////////////////////////////////////////*/
- System.out.println("x 的平方根 = "+Math.sqrt(x));
- System.out.println("x 的立方根: "+Math.pow(x,(1/3.0) ) );
- /*//////////////////////////////////////////// */
- System.out.println("x 與 y 兩者中較大的數 = "+Math.max(x,y));
- System.out.println("x 與 y 次方 = "+Math.pow(x,y));
- }
- }
複製代碼 |