• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Paul Clapham
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Roland Mueller
  • Piet Souris
Bartenders:

Question From Jaworski's Mock Test

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here's one that is driving me crazy... how would I have gone about finding the answer in a reasonable amount of time?
1. class Question {
2. public static void main(String[] args) {
3. for(int i = 0; i < 10; ++i) {
4. try {
5. if(i % 3 == 0) throw new Exception("E0");
6. try {
7. if(i % 3 == 1) throw new Exception("E1");
8. System.out.println(i);
9. }catch(Exception inner) {
10. i *= 2;
11. }finally {
12. ++i;
13. }
14. }catch(Exception outer) {
15. i +=3;
16. }finally {
17. ++i;
18. }
19. }
20. }
Which lines of output are displayed by the program above (select all that apply)?
A. 4
B. 5
C. 6
D. 7
E. 8
F. 9
Thank you,
Barbara
(The mock test gives the answer as B & E.)

[This message has been edited by Barbara Dyer-Bennet (edited September 14, 2000).]
 
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, Barbara,
The program is executed in following steps:
1) line3: ForInit part : i = 0; and ForExpression i < 10 is true
2) line5: i%3==0 is true, then throw an Exception
3) lint14: the Exception caught, then i += 3; so i = 3
4) line16: ++i, so i = 4;
5) line19: ForUpdate part: i++, so i = 5;
6) line3: and ForExpression i < 10 is true
7) line8: output : 5
8) lint11: finally ++i; so i = 6
9) line16: finally ++i, so i = 7;
10) line19: ForUpdate part: i++, so i = 8;
11) line3: and ForExpression i < 10 is true
12) line8: output : 8
13) lint11: finally ++i; so i = 9
14) line16: finally ++i, so i = 10;
15) line19: ForUpdate part: i++, so i = 11;
16) line3: and ForExpression i < 10 is false, for statement is end, and program is terminated.
Hope helpful!
Yiqing
 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
By the way, can u tell me how to get Jaworski's Mock Test?
Thanks
 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
my email: [email protected]
 
Sheriff
Posts: 5782
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The Jaworski's mock tests are here.
Ajith
 
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi yiqingye!
Your explanation of the question was quite good however I lost track line 4 .On line5 you mentioned "ForUpdate".What is that?
Please explain that .
Thanx in advance,
Ira
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic