返回列表 發帖
  1. public class TQC204
  2. {
  3.         public static void main(String[] args)
  4.         {
  5.                 int max=0;
  6.                 for(int i=0;i<args.length;i++)
  7.                 {
  8.                         if(Integer.parseInt(args[i])>max)
  9.                         {
  10.                                 max=Integer.parseInt(args[i]);
  11.                         }
  12.                 }
  13.                 System.out.println("===向日葵小班期末考風雲榜===\n");
  14.                 System.out.println("  本班最高分數:"+max);
  15.                 int min=1000;
  16.                 for(int i=0;i<args.length;i++)
  17.                 {
  18.                         if(Integer.parseInt(args[i])<min)
  19.                         {
  20.                                 min=Integer.parseInt(args[i]);
  21.                         }
  22.                 }
  23.                 System.out.println("  本班最低分數:"+min);
  24.                 int p=0;
  25.                 for(int i=0;i<args.length;i++)
  26.                 {
  27.                         if(Integer.parseInt(args[i])<60)
  28.                         {
  29.                                 p++;
  30.                         }
  31.                 }
  32.                 System.out.println("本班及格人數有"+p+"人60分以上");
  33.                 float tot=0;
  34.                 float avg=0;
  35.                 for(int i=0;i<args.length;i++)
  36.                 {
  37.                         tot+=Integer.parseInt(args[i]);
  38.                 }
  39.                 avg=tot/args.length;
  40.                 System.out.printf("  本班期末考總平均是:%.2f\n",avg);
  41.         }
  42. }
複製代碼
  1. import java.util.Scanner;
  2. public class TQC205
  3. {
  4.         public static void main(String[] args)
  5.         {
  6.                 System.out.println("請輸入兩個數字X和Y,用逗號隔開:");
  7.                 Scanner s=new Scanner(System.in);
  8.                 String g=s.nextLine();
  9.                 float y=0,x=0;
  10.                 String[] sa=g.split(",");
  11.                 try
  12.                 {
  13.                         x=Float.valueOf(sa[0]);
  14.                         y=Float.valueOf(sa[1]);
  15.                         System.out.println("x="+x);
  16.                         System.out.println("y="+y);
  17.                 }
  18.                 catch(Exception e)
  19.                 {
  20.                         System.out.println("輸入參數不正確");
  21.                         System.exit(0);
  22.                 }
  23.                 System.out.println("大於或等於X的最大整數是:"+Math.floor(x));
  24.                 System.out.println("大於或等於X的最小整數是:"+Math.ceil(x));
  25.                 System.out.println("最接近X的整數為:"+Math.rint(x));
  26.                 System.out.println("X的四捨五入值為:"+Math.round(x));
  27.                 System.out.println("X的平方根="+Math.sqrt(x));
  28.                 System.out.println("X的立方根="+Math.pow(x,(1/3.0)));
  29.                 System.out.println("X與Y兩者中較大的數="+Math.max(x,y));
  30.                 System.out.println("X的Y次方="+Math.pow(x,y));
  31.         }
  32. }
複製代碼
  1. public class TQC206 {
  2.         public static void main(String[] args) {
  3.                 try {
  4.                         if (args.length == 3) {
  5.                                 float a1 = Float.parseFloat(args[0]);
  6.                                 float a2 = Float.parseFloat(args[2]);
  7.                                 switch (args[1]) {
  8.                                 case "+":
  9.                                         System.out.println(a1 + "+" + a2 + "=" + (a1 + a2));
  10.                                         break;
  11.                                 case "-":
  12.                                         System.out.println(a1 + "-" + a2 + "=" + (a1 - a2));
  13.                                         break;
  14.                                 case "x":
  15.                                         System.out.println(a1 + "*" + a2 + "=" + (a1 * a2));
  16.                                         break;
  17.                                 case "/":
  18.                                         if (args[2].equals("0")) {
  19.                                                 System.out.println("除數不可為0");
  20.                                                 System.exit(0);
  21.                                         }
  22.                                         System.out.println(a1 + "/" + a2 + "=" + (a1 / a2));
  23.                                         break;
  24.                                 default:
  25.                                         System.out.println("引述格式不對,請使用如下格式");
  26.                                         System.out.println("Calc1+2");
  27.                                         break;
  28.                                 }
  29.                         } else {
  30.                                 System.out.println("引述格式不對,請使用如下格式");
  31.                                 System.out.println("Calc1+2");
  32.                         }
  33.                 } catch (Exception e) {
  34.                         System.out.println("引述格式不對,請使用如下格式");
  35.                         System.out.println("Calc1+2");
  36.                 }
  37.         }
  38. }
複製代碼
  1. public class TQC207
  2. {
  3.         public static void main(String[] args)
  4.         {
  5.                 int sum=0;
  6.                 int odd=0;
  7.                 int max=0;
  8.                 int tmp=0;
  9.                 int nums[]=new int[args.length];
  10.                 try
  11.                 {
  12.                         for(int i=0;i<args.length;i++)
  13.                         {
  14.                                 tmp=Integer.parseInt(args[i]);
  15.                                 nums[i]=tmp;
  16.                                 sum+=tmp;
  17.                                 if(tmp%2!=0)
  18.                                 {
  19.                                         odd ++;
  20.                                 }
  21.                                 max=Math.max(tmp,max);
  22.                         }
  23.                         System.out.println("最大值="+max);
  24.                         System.out.println("奇數的個數="+odd);
  25.                         System.out.println("數字的總合="+sum);
  26.                 }catch(Exception e)
  27.                 {
  28.                 }
  29.         }
  30. }
複製代碼
小雲雀

TOP

返回列表