返回列表 發帖

1217 try catch

本帖最後由 b790113g 於 2011-12-17 10:19 編輯 2 R2 W1 k; `5 ?8 R

) N6 w8 M$ \+ S1 N' j! `同上題# ?5 i. b5 Q; ?7 L% L. N& m
. O6 h+ k2 S, J5 M1 D
輸入兩個參數做數值運算
4 i1 `* q0 l$ D" U  W0 g+ `+ o: [# f/ m. N: n* t! l
若參數不足提示使用者
  1. public class d1217{

  2.     public static void main(String[] arg){
  3.         
  4.                 //if(arg.length<2) return ;
  5.      
  6.                 try{
  7.                         System.out.println(arg[0]+arg[1]);
  8.                 }catch(Exception e){
  9.                         System.out.println("參數不足"+e.toString());
  10.                 }
  11.         
  12.                
  13.     }

  14. }
複製代碼

  1. public class d1217{
  2.     public static void main(String[] arg){
  3.             //if(arg.length<2)return ;
  4.                 try{
  5.                     System.out.println(arg[0]+arg[1]);
  6.                 }catch(Excrption e){
  7.                 System.out.println("參數不足"+e.toString());
  8.         }
  9. }
複製代碼
★ 嘉凱~~☆

TOP

public class d1217{
5 |/ F$ g) L9 \, z" v! G/ X4 c% x/ E1 n. w
    public static void main(String[] arg){" E' H6 t+ l) b9 C# n7 F

, y) `3 I$ J# o            //if(arg.length<2)return ;
2 l2 c" I. E) t  ?! r( C9 M& ]1 J+ w- L( E+ ~
                try{
  E4 X$ ]! q, P# x- {0 q2 n! ^- `, a
                    System.out.println(arg[0]+arg[1]);( |0 }4 b! R" G2 s1 I

1 l$ W' P- w8 e8 M                }catch(Excrption e){7 @/ i5 \# I' D! ]1 ^8 a8 G

: m$ c( T0 C- s9 M$ {                System.out.println("參數不足)"+e.toString());
( L" f/ K2 I: d" O/ I
1 _7 g( ]& e$ x5 x        }
4 c% l0 ]) N, h0 c) _4 x- ~9 P0 g# o3 x: j* @3 m3 I
}
人平

TOP

public class d1217{( N9 C3 N. H7 x' |
* W3 j( ?! ^$ v0 L# k
    public static void main(String[] arg){6 E5 w/ W: m5 f1 d3 e3 V. o8 ~
% x5 u/ N; [2 d5 |
            //if(arg.length<2)return ;# {5 g+ b. i7 E$ i# |# M
/ b+ Z+ y! U6 L$ Y$ Z
                try{
' k) C: c/ e) r# G/ @2 Q5 l
, s; x0 S3 U& g                    System.out.println(arg[0]+arg[1]);# J8 E/ H% [  \7 K3 L! i
' Q9 m6 |4 q1 B( r, y
                }catch(Excrption e){
7 N) v  U' b4 Z( S7 M, Y/ ?
1 A( R  p, e2 `8 _3 _9 O                System.out.println("參數不足"+e.toString());7 X+ N! j% n: M: _, @" R6 K
4 o. g3 Z# g: t
        }7 g! \, ^4 K6 _4 A  i
, X! T6 R* W0 |. P2 Y* Y+ _
}
人平

TOP

  1. public class a1224
  2. {
  3.     public static void main(String[]arg)
  4.         {
  5.                 try
  6.                 {
  7.                 System.out.println(Integer.parseInt(arg[0])+Integer.parseInt(arg[1]));
  8.                 }
  9.             cath(Exception e)
  10.                 {
  11.                 System.out.println("參數不足");
  12.                 }
  13.     }




  14. }
複製代碼
水桶小鄭,鯰魚

TOP

  1. public class j3{
  2.         public static void main(String[] arg){
  3.                 try{
  4.                 System.out.println(Integer.parseInt(arg[0])+Integer.parseInt(arg[1]));
  5.         }catch(Exception e){
  6.          System.out.println("參數不足");
  7.         }
  8.         }
  9. }
複製代碼
陳彥綸

TOP

返回列表