- public class jva204 {
- public static void main(String[] args) {
- int max=0;
- int min=999;
- int pas=0;
- int tot=0;
- for(int i=0;i<args.length;i++){
- int s=Integer.parseInt(args[i]);
- if(s>max)max=s;
- if(s<min)min=s;
- if(s>60)pas++;
- tot+=s;
- }
- System.out.println("本班最高分:"+max);
- System.out.println("本班最低分:"+min);
- System.out.println("本班及格人數:"+pas);
- System.out.printf("本班總平均:%.2f",(float)tot/args.length);
- }
- }
複製代碼- import java.util.*;
- public class jva205 {
- public static void main(String[] args) {
- float x=0,y=0;
- System.out.println("輸入兩個數字x和y,並且以逗號隔開");
- Scanner s=new Scanner(System.in);
- String ss=s.next();
- String sa[]=ss.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 jva206 {
- public static void main(String[] args) {
- try{
- if(args.length==3){
- float a=Float.valueOf(args[0]);
- float b=Float.valueOf(args[2]);
- switch(args[1]){
- case"+":
- System.out.println(a+"+"+b+"="+(a+b));
- break;
-
- case"-":
- System.out.println(a+"-"+b+"="+(a-b));
- break;
- case"x":
- System.out.println(a+"*"+b+"="+(a*b));
- break;
- case"/":
- if(b==0)System.out.println("除數不可為0");
- System.out.println(a+"/"+b+"="+(a/b));
- break;
- default:
- System.out.println("引數格式不對,請使用如下格式\nCalc 1 + 2");
- break;
- }
- }else{
- System.out.println("引數格式不對,請使用如下格式\nCalc 1 + 2");
- }
- }catch(Exception e){
- System.out.println("引數格式不對,請使用如下格式\nCalc 1 + 2");
- }
- }
- }
複製代碼- public class jva207 {
- public static void main(String[] args) {
- int max=0;
- int odd=0;
- int sum=0;
- int tmp=0;
- int num[]=new int[args.length];
- for(int i=0;i<args.length;i++){
- tmp=Integer.parseInt(args[i]);
- num[i]=tmp;
- if(tmp%2!=0){
- odd++;
- }
- sum+=tmp;
- max=Math.max(max, tmp);
- }
- System.out.println("最大值="+max);
- System.out.println("奇數的個數="+odd);
- System.out.println("數字的總和="+sum);
- }
- }
複製代碼 |