|
|
发表于 2009-5-12 23:36:09
|
显示全部楼层
inspect应该不是这么用的,不知道你要解决什么问题,如果是要本程序内判断ci的大小,用if-else就可以了。如果ci不是本程序的,需要调用此程序时,可以用inspect,用法如下:3 z% t1 r0 D$ y- x3 x2 o. [" H
(number : integer)/ }+ M, I! _. ^6 Y/ v
is4 `# p9 k, K' L5 X! ?2 k: I
do6 S) c; P5 e# ?) @8 }
inspect number/ j9 q4 X( C: w$ b
when 1 then / \/ A% D0 i; a0 U, _3 u. N4 I
print "not a prime number"
* g" C( W# Y6 i0 ^. ]$ Z when 2,5,7,3 then & i* f/ a8 q7 b5 @0 q1 O$ P0 K
print "prime number"0 I1 k. M* e( D5 S, }, d! q
when 9,4 then
" k% o4 p' K. H3 p print "square number") V* B k4 K! h. }/ N
else
# m. k/ L; S/ H# X, G1 |. p1 f! V print "no special number";
7 a9 t& N8 K& ?! `! x print "or number greater than 9";
$ w; ]' P$ {9 O2 c- Y/ I; u7 S4 u end;
* N3 L' ?1 x/ A( y; X, l/ ~end; |
|