返回列表 發帖
  1. import java.util.*;
  2. public class tqc205
  3. {
  4.     public static void main(String args[])
  5.     {
  6.         float x,y;
  7.         System.out.println("輸入兩個數字x和y,以逗號分隔:");
  8.         Scanner s=new Scanner(System.in);
  9.         String va[]=s.next().split(",");
  10.         try
  11.         {
  12.              x=Float.parseFloat(va[0]);
  13.              y=Float.parseFloat(va[1]);
  14.              System.out.println("x= "+x);
  15.              System.out.println("y= "+y);
  16.         }catch(Exception e)
  17.         {
  18.              System.out.println("輸入參數不正確");
  19.              return;
  20.         }
  21.         System.out.println("小於或等於x的最大整數為: "+Math.floor(x));
  22.         System.out.println("大於或等於x的最大整數為: "+Math.ceil(x));
  23.         System.out.println("最接近x的整數為: "+Math.rint(x));
  24.         System.out.println("x的四捨五入值為: "+Math.round(x));
  25.         System.out.println("x的平方根= "+Math.sqrt(x));
  26.         System.out.println("x的立方根= "+Math.pow(x,1.0/3.0));
  27.         System.out.println("x與y兩者中較大的數= "+Math.max(x,y));
  28.         System.out.println("x的y次方= "+Math.pow(x,y));
  29.     }
  30. }
複製代碼

TOP

返回列表