返回列表 發帖

jva204~207

  1. public class jva204 {
  2.         public static void main(String[] args) {
  3.                 int max=0;
  4.                 int min=999;
  5.                 int pas=0;
  6.                 int tot=0;
  7.                 for(int i=0;i<args.length;i++){
  8.                         int s=Integer.parseInt(args[i]);
  9.                         if(s>max)max=s;
  10.                         if(s<min)min=s;
  11.                         if(s>60)pas++;
  12.                         tot+=s;
  13.                 }
  14.                 System.out.println("本班最高分:"+max);
  15.                 System.out.println("本班最低分:"+min);
  16.                 System.out.println("本班及格人數:"+pas);
  17.                 System.out.printf("本班總平均:%.2f",(float)tot/args.length);
  18.         }
  19. }
複製代碼
  1. import java.util.*;
  2. public class jva205 {
  3.         public static void main(String[] args) {
  4.                 float x=0,y=0;
  5.                 System.out.println("輸入兩個數字x和y,並且以逗號隔開");
  6.                 Scanner s=new Scanner(System.in);
  7.                 String ss=s.next();
  8.                 String sa[]=ss.split(",");
  9.                 try{
  10.                         x=Float.valueOf(sa[0]);
  11.                         y=Float.valueOf(sa[1]);
  12.                         System.out.println("x="+x);
  13.                         System.out.println("y="+y);
  14.                 }catch(Exception e){
  15.                         System.out.println("參數錯誤!");
  16.                         System.exit(0);
  17.                 }
  18.                 System.out.println("小於或等於x的最大整數為"+Math.floor(x));
  19.                 System.out.println("大於或等於x的最小整數為"+Math.ceil(x));
  20.                 System.out.println("最接近x的整數為"+Math.rint(x));
  21.                 System.out.println("x的四捨五入值為"+Math.round(x));
  22.                 System.out.println("x的平方根為"+Math.sqrt(x));
  23.                 System.out.println("x的立方根為"+Math.pow(x, (1/3.0)));
  24.                 System.out.println("x和y兩者中較大的數為"+Math.max(x,y));
  25.                 System.out.println("x的y次方為"+Math.pow(x, y));
  26.         }
  27. }
複製代碼
  1. public class jva206 {
  2.         public static void main(String[] args) {
  3.                 try{
  4.                         if(args.length==3){
  5.                                 float a=Float.valueOf(args[0]);
  6.                                 float b=Float.valueOf(args[2]);
  7.                                 switch(args[1]){
  8.                                 case"+":
  9.                                         System.out.println(a+"+"+b+"="+(a+b));
  10.                                         break;
  11.                                
  12.                         case"-":
  13.                                 System.out.println(a+"-"+b+"="+(a-b));
  14.                                 break;
  15.                 case"x":
  16.                         System.out.println(a+"*"+b+"="+(a*b));
  17.                         break;
  18.         case"/":
  19.                 if(b==0)System.out.println("除數不可為0");
  20.                 System.out.println(a+"/"+b+"="+(a/b));
  21.                 break;
  22.                 default:
  23.                         System.out.println("引數格式不對,請使用如下格式\nCalc 1 + 2");
  24.                         break;
  25.                                 }
  26.                         }else{
  27.                                 System.out.println("引數格式不對,請使用如下格式\nCalc 1 + 2");
  28.                         }
  29.                 }catch(Exception e){
  30.                         System.out.println("引數格式不對,請使用如下格式\nCalc 1 + 2");
  31.                 }
  32.         }
  33. }
複製代碼
  1. public class jva207 {
  2.         public static void main(String[] args) {
  3.                 int max=0;
  4.                 int odd=0;
  5.                 int sum=0;
  6.                 int tmp=0;
  7.                 int num[]=new int[args.length];
  8.                 for(int i=0;i<args.length;i++){
  9.                         tmp=Integer.parseInt(args[i]);
  10.                         num[i]=tmp;
  11.                         if(tmp%2!=0){
  12.                                 odd++;
  13.                         }
  14.                         sum+=tmp;
  15.                         max=Math.max(max, tmp);
  16.                 }
  17.                 System.out.println("最大值="+max);
  18.                 System.out.println("奇數的個數="+odd);
  19.                 System.out.println("數字的總和="+sum);
  20.         }
  21. }
複製代碼
陳彥綸

TQC204
  1. public class jva204 {
  2.         public static void main(String[] args) {
  3.                 int max=0;
  4.                 int min=999;
  5.                 int pas=0;
  6.                 int tot=0;
  7.                 for(int i=0;i<args.length;i++){
  8.                         int s=Integer.parseInt(args[i]);
  9.                         if(s>max)max=s;
  10.                         if(s<min)min=s;
  11.                         if(s>60)pas++;
  12.                         tot+=s;
  13.                 }
  14.                 System.out.println("本班最高分:"+max);
  15.                 System.out.println("本班最低分:"+min);
  16.                 System.out.println("本班及格人數:"+pas);
  17.                 System.out.printf("本班總平均:%.2f",(float)tot/args.length);
  18.         }
  19. }
複製代碼
TQC205
  1. import java.util.*;
  2. public class TQC205 {
  3.         public static void main(String[] args) {
  4.                 float x=0,y=0;
  5.                 System.out.println("輸入兩個數字x和y,並且以逗號隔開");
  6.                 Scanner s=new Scanner(System.in);
  7.                 String ss=s.next();
  8.                 String sa[]=ss.split(",");
  9.                 try{
  10.                         x=Float.valueOf(sa[0]);
  11.                         y=Float.valueOf(sa[1]);
  12.                         System.out.println("x="+x);
  13.                         System.out.println("y="+y);
  14.                 }catch(Exception e){
  15.                         System.out.println("參數錯誤!");
  16.                         System.exit(0);
  17.                 }
  18.                 System.out.println("小於或等於x的最大整數為"+Math.floor(x));
  19.                 System.out.println("大於或等於x的最小整數為"+Math.ceil(x));
  20.                 System.out.println("最接近x的整數為"+Math.rint(x));
  21.                 System.out.println("x的四捨五入值為"+Math.round(x));
  22.                 System.out.println("x的平方根為"+Math.sqrt(x));
  23.                 System.out.println("x的立方根為"+Math.pow(x, (1/3.0)));
  24.                 System.out.println("x和y兩者中較大的數為"+Math.max(x,y));
  25.                 System.out.println("x的y次方為"+Math.pow(x, y));
  26.         }
  27. }
複製代碼
TQC206
  1. public class TQC206 {
  2.         public static void main(String[] args) {
  3.                 try{
  4.                         if(args.length==3){
  5.                                 float a=Float.valueOf(args[0]);
  6.                                 float b=Float.valueOf(args[2]);
  7.                                 switch(args[1]){
  8.                                 case"+":
  9.                                         System.out.println(a+"+"+b+"="+(a+b));
  10.                                         break;
  11.                                 
  12.                         case"-":
  13.                                 System.out.println(a+"-"+b+"="+(a-b));
  14.                                 break;
  15.                 case"x":
  16.                         System.out.println(a+"*"+b+"="+(a*b));
  17.                         break;
  18.         case"/":
  19.                 if(b==0)System.out.println("除數不可為0");
  20.                 System.out.println(a+"/"+b+"="+(a/b));
  21.                 break;
  22.                 default:
  23.                         System.out.println("引數格式不對,請使用如下格式\nCalc 1 + 2");
  24.                         break;
  25.                                 }
  26.                         }else{
  27.                                 System.out.println("引數格式不對,請使用如下格式\nCalc 1 + 2");
  28.                         }
  29.                 }catch(Exception e){
  30.                         System.out.println("引數格式不對,請使用如下格式\nCalc 1 + 2");
  31.                 }
  32.         }
  33. }
複製代碼
TQC207
  1. public class TQC207 {
  2.         public static void main(String[] args) {
  3.                 int max=0;
  4.                 int odd=0;
  5.                 int sum=0;
  6.                 int tmp=0;
  7.                 int num[]=new int[args.length];
  8.                 for(int i=0;i<args.length;i++){
  9.                         tmp=Integer.parseInt(args[i]);
  10.                         num[i]=tmp;
  11.                         if(tmp%2!=0){
  12.                                 odd++;
  13.                         }
  14.                         sum+=tmp;
  15.                         max=Math.max(max, tmp);
  16.                 }
  17.                 System.out.println("最大值="+max);
  18.                 System.out.println("奇數的個數="+odd);
  19.                 System.out.println("數字的總和="+sum);
  20.         }
  21. }
複製代碼
★ 嘉凱~~☆

TOP

  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

  1. import java.lang.*;
  2. import java.util.*;

  3. public class TQC207
  4. {
  5.          public static void main(String args[])
  6.          {
  7.                  int x, i,max=0, odd=0, sum=0;
  8.                  for(i=0;i<args.length;i++)
  9.                  {
  10.                  x=Integer.valueOf(args[i]);
  11.           sum+=x;
  12.           if(x%2==1)
  13.           {
  14.                   odd++;
  15.           }
  16.           max=Math.max(max,x);
  17.           }
  18.           System.out.println("最大值"+"="+max);
  19.           System.out.println("奇數的個數"+"="+odd);
  20.           System.out.println("數字總和"+"="+sum);
  21.          
  22.          }
  23.         
  24.       
  25. }
複製代碼

TOP

  1. import java.util.Arrays;

  2. public class TQC204
  3. {
  4.    public static void main(String args[])
  5.    {
  6.    
  7.       int score[];
  8.       int tmp=0 , sum=0 , pass=0, max=0, min=Integer.parseInt(args[0]);
  9.       double avg = 0.0;
  10.       int amt = args.length;
  11.       score = new int[amt];
  12.    
  13.       for(int i = 0 ; i<amt ; i++ )
  14.       {
  15.          tmp = Integer.parseInt( args[i] );
  16.          score[i] = tmp;
  17.          sum += tmp;
  18.          max=Math.max(max,tmp);
  19.          min=Math.min(min,tmp);
  20.          if(tmp>=60)
  21.             pass++;
  22.       }
  23.       avg=(double)sum/amt;
  24.       /* use Arrays.sort to replace line 19,20ß
  25.       Arrays.sort(score);
  26.       max = score[amt-1];
  27.       min = score[0];
  28.       */
  29.       
  30.       System.out.println("===向日葵小班期末考風雲榜===\n");
  31.       System.out.println(" 本班最高分數是:"+max);
  32.       System.out.println(" 本班最低分數是:"+min);
  33.       System.out.println(" 本班及格人數有"+ pass +"人60分以上");
  34.       System.out.printf(" 本班期末考總平均是:%.2f\n", avg );
  35.    }

  36. }
複製代碼

TOP

  1. import java.lang.*;
  2. import java.util.*;
  3. public class TQC206
  4. {
  5.        public static void main(String args[])
  6.        {
  7.                   int x, y;
  8.                   //System.out.println(args[1]);
  9.                   if(args.length !=3)
  10.                  {
  11.                          System.out.println("輸入錯誤!");
  12.                  }
  13.                  else
  14.                  {
  15.                  try
  16.                  {
  17.                   x=Integer.valueOf(args[0]);
  18.                   y=Integer.valueOf(args[2]);
  19.                  if(args[1].equals("+"))
  20.                  {
  21.                          System.out.println(x+"+"+y+"="+(x+y));
  22.                  }
  23.                  else if(args[1].equals("-"))
  24.                  {
  25.                          System.out.println(x+"-"+y+"="+(x-y));
  26.                  }
  27.            else if(args[1].equals("x"))
  28.                  {
  29.                          System.out.println(x+"x"+y+"="+(x*y));
  30.                  }
  31.                  else if(args[1].equals("/"))
  32.                  {
  33.                  if(y==0)
  34.                  {
  35.                  System.out.println("除數不可為0");
  36.                  }else
  37.                  System.out.println(x+"/"+y+"="+(x/y));
  38.                  }
  39.                  else
  40.                  {
  41.                          System.out.println("輸入錯誤2!");
  42.                  }
  43.                  
  44.                }catch(Exception e)
  45.                {
  46.                        System.out.println("輸入錯誤3!");
  47.                }
  48.               }
  49.     }
  50.       
  51. }
複製代碼

TOP

返回列表