- import java.util.*;
- public class tqc205
- {
- public static void main(String args[])
- {
- float x,y;
- System.out.println("輸入兩個數字x和y,以逗號分隔:");
- Scanner s=new Scanner(System.in);
- String va[]=s.next().split(",");
- try
- {
- x=Float.parseFloat(va[0]);
- y=Float.parseFloat(va[1]);
- System.out.println("x= "+x);
- System.out.println("y= "+y);
- }catch(Exception e)
- {
- System.out.println("輸入參數不正確");
- return;
- }
- 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.0/3.0));
- System.out.println("x與y兩者中較大的數= "+Math.max(x,y));
- System.out.println("x的y次方= "+Math.pow(x,y));
- }
- }
複製代碼 |