返回列表 發帖
  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.min(x,y));
  29.         System.out.println("x 的 y 次方="+Math.pow(x,y));
  30.     }
  31. }
複製代碼

TOP

返回列表