返回列表 發帖

1217 try catch

本帖最後由 b790113g 於 2011-12-17 10:19 編輯
6 E* C$ F; t, d& l& z1 u# l# M1 R
同上題
, t% \/ v! y3 c( E, v' a1 E7 X7 J" T8 n6 u' M" M& ?
輸入兩個參數做數值運算
. v9 X9 O6 H; l6 |4 {
  q5 u* _! K5 c1 Z' \: a若參數不足提示使用者
  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{
; \* ?" Y# X! L& j& F4 H" p. E$ f1 c4 i7 S' y' k
    public static void main(String[] arg){- L4 t# V: T, u2 x1 o

7 V) I- B# E6 ]+ N- A            //if(arg.length<2)return ;
5 m/ V1 Q) ~2 |9 }" L9 d$ w6 i8 `$ e0 h' s
                try{
8 ~3 [# z( B& {6 w/ A5 d2 {0 S+ Q6 @$ U
                    System.out.println(arg[0]+arg[1]);$ n( E6 w/ ]7 x6 d; _) m, [9 o
0 m) Q  a$ H. e) q  D+ d6 a. [
                }catch(Excrption e){
4 {. ?% Y, V( ~: s) E
9 E& e5 U' c( Z, e# Z7 L  e- f9 }                System.out.println("參數不足)"+e.toString());- w6 \3 n5 ]) C, c

) P* h; t# o% W! h: s( b( y' U* N        }
6 y0 U, C# I# w8 g
% D* }. u+ x& ]9 k) B! U}
人平

TOP

public class d1217{
6 _( _1 ?  y& z* s: s" ~6 t) _8 w  G. Q) r  L/ p
    public static void main(String[] arg){
$ |5 K6 A: L: t6 `+ Q9 }
* [. T6 M8 v8 K, z0 O! U- Y            //if(arg.length<2)return ;) O6 s6 B  ~9 q5 E* s) {& C

3 v: l3 `9 E  v                try{
# @* x2 X; _! F
6 v3 ]% x  M5 f/ [' S3 f                    System.out.println(arg[0]+arg[1]);
) s8 u* c( z" R5 M% K1 o3 I" A+ H
) r9 I: O) s/ ]8 ]                }catch(Excrption e){
7 c4 W6 H( Y$ C* p0 y1 n$ }9 |9 F8 J# }4 U) f  w2 `7 R
                System.out.println("參數不足"+e.toString());
( `- j+ p- A, P0 L  d. A# W2 a/ T% N9 W. e" T+ c# f0 g' L) j
        }
% w# c5 D+ a1 P" `& d& q
2 Z( l6 ~- d& w5 l}
人平

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

返回列表