- import java.util.*;
- public class TQC205 {
- public static void main(String arg[]){
- 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]);
- System.out.println("x="+x);
- System.out.println("y="+y);
- }catch(Exception e){
- System.out.println("輸入參數不正確");
- System.exit(0);
- }
- 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.max(x,y));
- }
- }
複製代碼 |