返回列表 發帖

1217 try catch

本帖最後由 b790113g 於 2011-12-17 10:19 編輯 - O' Z. r% ?) d' d
" k$ S) V5 V. K/ M- c5 ]' K0 R
同上題
/ x- X$ g$ {* ?; K8 G
3 _' R, a! O4 k, m3 A% A0 t4 s/ w輸入兩個參數做數值運算  `, a  o' w" _9 ?  u0 x
. E' }' z& r! n1 z! ^9 h! t
若參數不足提示使用者
  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- C! V1 O' a/ b) \  X) P9 @7 t+ A+ b3 t# ?; Z6 i
    public static void main(String[] arg){
, a: l" _8 R- j5 _( z" e' E7 p5 r5 b
            //if(arg.length<2)return ;
& c, f1 G) }  V; v0 I; m
$ d5 u( j3 z" ~  R. W- B                try{0 W& q' l. Z  r. x: E1 ~/ H

, b# e& C6 q/ ^7 F' v* ]4 b% O                    System.out.println(arg[0]+arg[1]);
6 R5 X6 c2 q, G$ _4 J5 b
; r2 g# P# b" t/ W8 z2 N                }catch(Excrption e){
  t  |& @5 }& f8 j1 G1 Z6 i+ {
6 u! b: c# |- \1 j) K                System.out.println("參數不足)"+e.toString());
" |6 T' c3 }) P9 I% @
( ^. m# z. F, V+ H        }& x  t& R5 N2 b) E* d

% ~0 e) o) d$ n/ V}
人平

TOP

public class d1217{
# V4 Y$ o8 a" a* O' j* E  ?  T) a, W3 Q
    public static void main(String[] arg){) ~8 s# }$ y" }  T8 e; f, w

; g' k9 |1 T8 q% V: B4 X            //if(arg.length<2)return ;0 I+ N9 D8 @9 Y
( {; W' V- v! ^, r# P
                try{
9 q3 _1 ~+ S% H9 m" @& P6 i% m3 w/ U/ c3 Q$ ?( q0 X; b
                    System.out.println(arg[0]+arg[1]);
/ R2 H1 a% B. F: [! x2 T1 G+ V3 s2 d; `3 o9 {$ L- M- U
                }catch(Excrption e){( j0 _" B/ Q, n* D
0 A8 ], l% i$ g$ z! x7 S
                System.out.println("參數不足"+e.toString());9 e) |( ]* J6 l  G# W( u
# P3 g  a, S2 W: k: n9 |
        }
, r, N% O# N3 R& r  Z( R) e
4 t0 k" G5 C/ ~# u8 A}
人平

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

返回列表