- public class TQC204
- {
- public static void main(String[] args)
- {
- int max=0;
- for(int i=0;i<args.length;i++)
- {
- if(Integer.parseInt(args[i])>max)
- {
- max=Integer.parseInt(args[i]);
- }
- }
- System.out.println("===向日葵小班期末考風雲榜===\n");
- System.out.println(" 本班最高分數:"+max);
- int min=1000;
- for(int i=0;i<args.length;i++)
- {
- if(Integer.parseInt(args[i])<min)
- {
- min=Integer.parseInt(args[i]);
- }
- }
- System.out.println(" 本班最低分數:"+min);
- int p=0;
- for(int i=0;i<args.length;i++)
- {
- if(Integer.parseInt(args[i])<60)
- {
- p++;
- }
- }
- System.out.println("本班及格人數有"+p+"人60分以上");
- float tot=0;
- float avg=0;
- for(int i=0;i<args.length;i++)
- {
- tot+=Integer.parseInt(args[i]);
- }
- avg=tot/args.length;
- System.out.printf(" 本班期末考總平均是:%.2f\n",avg);
- }
- }
複製代碼- import java.util.Scanner;
- public class TQC205
- {
- public static void main(String[] args)
- {
- 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.pow(x,y));
- }
- }
複製代碼- public class TQC206 {
- public static void main(String[] args) {
- try {
- if (args.length == 3) {
- float a1 = Float.parseFloat(args[0]);
- float a2 = Float.parseFloat(args[2]);
- switch (args[1]) {
- case "+":
- System.out.println(a1 + "+" + a2 + "=" + (a1 + a2));
- break;
- case "-":
- System.out.println(a1 + "-" + a2 + "=" + (a1 - a2));
- break;
- case "x":
- System.out.println(a1 + "*" + a2 + "=" + (a1 * a2));
- break;
- case "/":
- if (args[2].equals("0")) {
- System.out.println("除數不可為0");
- System.exit(0);
- }
- System.out.println(a1 + "/" + a2 + "=" + (a1 / a2));
- break;
- default:
- System.out.println("引述格式不對,請使用如下格式");
- System.out.println("Calc1+2");
- break;
- }
- } else {
- System.out.println("引述格式不對,請使用如下格式");
- System.out.println("Calc1+2");
- }
- } catch (Exception e) {
- System.out.println("引述格式不對,請使用如下格式");
- System.out.println("Calc1+2");
- }
- }
- }
複製代碼- public class TQC207
- {
- public static void main(String[] args)
- {
- int sum=0;
- int odd=0;
- int max=0;
- int tmp=0;
- int nums[]=new int[args.length];
- try
- {
- for(int i=0;i<args.length;i++)
- {
- tmp=Integer.parseInt(args[i]);
- nums[i]=tmp;
- sum+=tmp;
- if(tmp%2!=0)
- {
- odd ++;
- }
- max=Math.max(tmp,max);
- }
- System.out.println("最大值="+max);
- System.out.println("奇數的個數="+odd);
- System.out.println("數字的總合="+sum);
- }catch(Exception e)
- {
- }
- }
- }
複製代碼 |