返回列表 發帖

106 數值過濾器

本帖最後由 b790113g 於 2011-12-31 12:07 編輯 , C+ e+ M- M/ p4 W. h( Y
( b$ [8 [  i  K% g2 P/ w
不是數字就別加總' B6 B( n, T9 p9 ~
' P2 n& C# ]! l2 a6 z1 a
附件: 您需要登錄才可以下載或查看附件。沒有帳號?註冊

  1. public class jva106
  2. {
  3.         public static void main(String arg[])
  4.         {
  5.         int tot=0;
  6.         int isn=0;
  7.         int non=0;
  8.                 for(int i=0;i<arg.length;i++)
  9.                 {
  10.                         try{
  11.                         tot=tot+Integer.parseInt(arg[i]);
  12.                         isn++;
  13.                         }catch(Exception e){
  14.                         non++;
  15.                         }
  16.                 }
  17.         System.out.println("數值之總和為:"+tot);
  18.         System.out.println("非數值個數為:"+non);
  19.         System.out.println("純數之個數為:"+isn);
  20.        
  21.         }
  22. }
複製代碼
救命!!!!!!!!為什麼不能執行 - ]" o% j. O( }, y1 W- G: B9 H
阿阿阿阿阿阿阿阿阿阿阿阿
水桶小鄭,鯰魚

TOP

返回列表