返回列表 發帖

1217 try catch

本帖最後由 b790113g 於 2011-12-17 10:19 編輯 : S4 t, K; m1 D7 l
, G  N3 _) y/ d2 ]9 s' U  T/ j  G
同上題
4 R' h& i+ b0 _* ^7 A1 T+ Q/ V6 u, W6 n* ?; ~
輸入兩個參數做數值運算/ Z, t6 ?8 D0 Y9 R* a
7 q/ x% z# u: m: ~
若參數不足提示使用者
  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{
' S  ]: L# n1 `1 p: t2 i3 C" _* G# t1 N! Q; N
    public static void main(String[] arg){7 l  P% S% B( e- s1 l9 k
4 V7 |# O" ^' c0 E6 Q( e
            //if(arg.length<2)return ;
  U- N4 V0 v" ^' L! }" o4 a6 G* E9 V4 ^
                try{7 j' H+ Q4 t( |* }8 ^" L8 ?/ [# a

3 {# t- F# |: Y" e1 ]                    System.out.println(arg[0]+arg[1]);) V- W( s& k1 x( z/ ^
/ e& q7 l4 T3 e2 K
                }catch(Excrption e){- d6 h7 P/ ?+ A6 V; \: r1 P  M& \

+ _, b; z3 R% d5 i/ l) W                System.out.println("參數不足)"+e.toString());& Z' d! h  X# ?9 U/ U+ ?5 a/ |
2 V( T: @: s) d; A
        }
: V4 m3 u! A/ P8 {8 {
( D  q& h+ {" h0 Q5 K0 G( {}
人平

TOP

public class d1217{
; t4 E! b# _3 u% m6 _! m) z  U2 W; E9 z7 ?0 p! X
    public static void main(String[] arg){2 s3 J: ~& I; l
) T4 w8 Y" Y+ ~. u/ `
            //if(arg.length<2)return ;
3 J  d. \3 z1 b" x/ R: a# j; C1 w' S3 M+ P, l/ K
                try{
9 P' i! u2 [0 m8 I% G% r, ~2 K( g' H3 h+ c2 q6 R. }
                    System.out.println(arg[0]+arg[1]);" [% D  ?$ U6 ]5 q" s5 h
' `* ^* d- {2 x8 `; c
                }catch(Excrption e){
$ m6 ~5 D" M) N' @! A
) k4 r; C; P- u/ B                System.out.println("參數不足"+e.toString());
9 q4 L% V& [) N$ i
; v" I* O6 W2 K* X, t        }
: q0 E$ P% g9 u% t& Q  i, I* o8 A% X) t" A. v' P
}
人平

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

返回列表