310-025精选题(51)的具体内容如下:+ ]* z& Q! a# | m* g
229. Consider the following code: What will be printed?
, B! V+ I, i5 G7 Q0 i( }. I- kpublic class StringTest{
! T' M+ z" s0 n1 V7 T; {7 }4 ^public static void main(String[] args){
# D) d6 l2 x) c- u9 X; s# i8 u8 cString s = "Kalle och Matte";+ \& Y0 }- a! C
int i = s.length();( ~' H' M0 |+ x a( ^
int j = args.length;* N E7 e, d& S7 Y9 _) e
System.out.println(i + " " + j);4 ~) K x) N, S. U& Q
}}
! {- d4 e* _# M- w5 [. O( \( |A. 13 13
7 J4 j" Z4 H( W- OB. 13 0
, C+ S: E, \, c. KC. 15 06 o. C4 S* p0 y9 b' h L9 J
D. 15 13- M0 J. q$ O" q. n
E. 15 null
$ i5 ]) _& _% C6 U* R* Y1 z- PF. 15 + + 0
- R i! d9 q3 l5 @G. 13 + + 0& t, M1 f; D j# W6 w: D, C
C.
6 z$ ^3 l! n/ O230. Check and run this code and you will see how the round method in the Java.lang.Math class will behave when you have -4.5 and 4.5 . It will round up. You will alse see how substring();floor();and ceil();behave.8 A2 S' |# T* t& z4 n% r/ t
import java.lang.Math;- X9 O; W, d1 Y- r B7 Z' A, J& r5 H
public class Substr{8 Z2 r. B: f# P1 Q
public static void main(String[]args){" D: E9 ]0 V& a
String s1 = ("Kalle Bengtsson");+ f9 B9 s+ Y. a, Z6 L6 z: \
String s2 = s1.substring(0,5);
- `- x1 o! C9 U! j$ pSystem.out.println(s2); `/ U1 ^5 N8 p% Z! O
s1 = ("phenobarbital(");# x0 M3 X% ^ R6 |2 w- A& ^
s2 = s1.substring(3,5);
) q$ r1 a3 m. |3 OSystem.out.println(s2);
0 ^- I O$ w( R# ulong i = Math.round(-4.4);
$ r! J! `8 h7 m2 Y2 H! ?System.out.println("Math.round(-4.4) = " + i);0 Z. S' V W' a% n7 X: l P
long j = Math.round(4.5);
0 B$ p: P7 d5 O1 ^/ t5 \! c: rSystem.out.println("Math.round(4.5) = " + j);1 G. R; U# q3 P9 k4 S
long k = Math.round(-4.5);, m0 w( R3 e: q
System.out.println("Math.round(-4.5) = " + k);
r& _" @* W7 ]& R6 e: yint l = (int)(Math.ceil(-4.4));
! r- l q' w) A5 V. uSystem.out.println("Math.ceil(-4.4) = " + l);6 u. r, T# G" ~6 q2 r0 B
int m = (int)Math.ceil(-4.5);
4 u, v% ?, l( Y$ O2 H( ESystem.out.println("Math.ceil(-4.5) = " + m);
! Q# B. _; {( r, `( c# w/ [int n = (int)Math.ceil(4.4);
, c4 D6 e/ l2 {# oSystem.out.println("Math.ceil(4.4) = " + n);+ N0 Z: p& o% }0 Q+ J& y7 c
int o = (int)Math.floor(-4.4);
' B# i1 K3 _% J) \6 o* nSystem.out.println("Math.floor(-4.4) = " + o);
M. J3 o* }) r ~' ~/ X$ pint p = (int)Math.floor(4.4);
8 {. V! _- A) ^6 H& ]( LSystem.out.println("Math.floor(4.4) = " + p);; M+ c$ X. G* K7 t- U
int q = (int)Math.floor(4.5);
; P- \1 k$ f8 q9 TSystem.out.println("Math.floor(4.5) = " + q);
5 t3 T2 h6 u% C- A: ]}* x3 Z* y8 @6 U
} |