返回列表 發帖

1217 try catch

本帖最後由 b790113g 於 2011-12-17 10:19 編輯
5 q2 F# [/ \/ T) N9 g. h, h7 X0 H2 r! ?' a. X
同上題
$ j2 [" g8 }! T5 h- H5 j5 ]/ |5 D" y  P, `; L0 m  W
輸入兩個參數做數值運算
0 i" n) s" Q1 {  b; {' @" \, R% E8 Q
若參數不足提示使用者
  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{
' K( N0 d/ b: J, k1 n1 T4 }( w6 x0 h* P9 r2 L) r! k' J
    public static void main(String[] arg){( X4 P1 |% L5 K* A
% {: H/ h/ w9 T
            //if(arg.length<2)return ;6 k& B8 ]! J' S1 O, I

  Q$ `' D1 E; {8 u                try{: c9 A  }9 ]+ ]# w
: h8 d, ^: V9 {
                    System.out.println(arg[0]+arg[1]);6 A; L% J) l  A' ~$ E

3 r" w2 e. K  e' f1 Q! x  I                }catch(Excrption e){
( |2 ~: u5 v9 L: ?8 x6 v9 q0 b0 d0 U: s, g2 R
                System.out.println("參數不足)"+e.toString());8 j1 g) f4 f1 {' R  c

" H+ V0 }0 f  ^+ ]4 f! r/ }        }: N  R3 }4 j( m
" P! X. v2 m& Y7 N+ c& [
}
人平

TOP

public class d1217{
; I3 T* I9 T. l- S; }* T4 N, M( b& P
    public static void main(String[] arg){
- e) |  h! P8 l  o5 E; k6 z) A! H$ F% u( L0 h
            //if(arg.length<2)return ;
  L! ]4 t! q8 M5 {$ Y, w
4 ~% M+ R, ^+ b8 F/ t$ f( C# d                try{- a4 {- {7 S3 w$ Z. L2 t2 U$ ~
0 p! {( h7 z- {! I: e$ ^
                    System.out.println(arg[0]+arg[1]);* Z1 S4 A" r! ~" T7 d5 M. I) N

0 @, |+ w9 G* V                }catch(Excrption e){0 p7 z  ]0 s1 g9 S2 D* c0 k

0 g' Y* \4 D: H; `                System.out.println("參數不足"+e.toString());2 H3 G, K- d7 t: o+ u: g8 C* E
/ U- z! e7 [# Y2 m8 B% A$ Z
        }
7 D# |- x% j  ~6 @
  }8 X& _. w5 @8 ~}
人平

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

返回列表