a我考网

 找回密码
 立即注册

QQ登录

只需一步,快速开始

扫一扫,访问微社区

查看: 88|回复: 1

[考试试题] JAVA认证历年真题:310-025精选题(51)

[复制链接]
发表于 2012-8-4 12:33:16 | 显示全部楼层 |阅读模式
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
}
回复

使用道具 举报

 楼主| 发表于 2012-8-4 12:33:17 | 显示全部楼层

JAVA认证历年真题:310-025精选题(51)

231. Consider the following code: What will be printed?
8 R/ f9 t# {- s/ N* s2 o$ Gpublic class Testa{
7 I* F9 G: p4 U6 B% xInteger a = 10;
8 z4 _5 z; P0 Y. |: RInteger b = 20;, B$ W' x5 l# b$ `4 i$ T- Z+ h
Integer c = 10;
( ?% R% ^+ n5 s, E2 H! @5 Tpublic static void main (String[] args){
( ^9 }9 D% m: x; B1 m3 }if (a==c){( `- h' D5 q# ]/ k# V
System.out.println("Fel");
& [. t* y* J) z3 b. j* p0 B! z}
1 z+ \5 \2 m" f3 L( Oif (a.equals(c)){7 {7 |6 q5 R+ [+ m
System.out.println("rätt");
0 a. T6 j2 s7 I5 ]  K}
% H5 L1 R* u7 q9 F: I) I}
$ ^5 }9 \9 }7 w+ z  M+ q5 J}
# k* I) ^# @9 L* C9 Y' }A. Fel rätt
% X' s  k5 Y, K( f( D; RB. rätt
% A* t  N$ x8 w9 Y! o& eC. Fel
/ L3 F$ w7 n* \4 |% a- zD. None will be printed. A NullPointerException will be thrown.
' f# S) u& x! Y! m3 U, pE. None will be printed. Compilation error. Incompatible types and a non-static variable cannot be referenced from a static context.4 Y+ y" g/ N4 p6 n) j1 f
E. (check)0 p0 k% q& h* C) G+ S7 u
232. Consider the following code: What ()will be printed?* I4 c8 q8 M7 Y- ]3 e! e) M
public class Testb {
* ^6 n( m* w9 i7 f) ^/ R% Sstatic Integer a = 10;
7 Q& ^9 d+ l& X, ~static Integer b = 20;
3 t" I* _8 Y. f7 ?static Integer c = 10;
, f/ {- b$ _: \- R; ~) M+ Zpublic static void main (String[] args){* I  E2 r" J" }, a3 Z
if (a==c){2 C8 V& c7 ~, H5 C% N0 X# R. ]8 l
System.out.println("Fel");
9 Z+ [. o: M3 _4 i}) p6 D7 M: U5 t) L" o" C- s2 J
if (a.equals(c)){, Q- O. h; P- V! W! U9 N
System.out.println("rätt");
  |+ v* ^4 A7 [% s' T" ]; v}
& A* g: Z# ]6 _3 C3 s}* n' h- g3 _+ |- k3 j3 j
}3 |0 i% |4 g8 t* D& x
A. Fel rätt
0 y# `! Y8 f1 C/ A, OB. rätt
, `3 m3 e# G( C+ E! {C. Fel
; H' l* |5 `6 s' T" p7 b' F! F* }D. None will be printed. A NullPointerException will be thrown., Y5 b* \2 Y, k/ f& f/ Y
E. None will be printed. Compilation error. Incompatible types and a non-static variable cannot be referenced from a static context.. r4 j! o; a: w+ y$ F! P% m
F. None will be printed. Compilation error. Incompatible types.+ V# f* U' K  R) M' w
F.
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|手机版|小黑屋|Woexam.Com ( 湘ICP备18023104号 )

GMT+8, 2024-5-19 03:41 , Processed in 0.268974 second(s), 23 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表