• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

dan chrisholm's mock exam 1

 
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
this is regarding mock exam 1 on july 4 question #1:
the answer that is given is : b,x,F,Y,S
I compiled the program and the output was:
b,y,F,Y,S
can anyone please clarify this question ?
 
Ranch Hand
Posts: 3271
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Maria, I got the given answer: "b,x,F,Y,S" when I executed this code. Are you sure you're running the code just as it is given?
Corey
 
Maria Garcia
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
yeah, i just copied n pasted it.
 
Ranch Hand
Posts: 1055
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Maria,
Can you post the code again or at least a link to it?
 
Maria Garcia
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
http://www.geocities.com/danchisholm2000/july4/exam1.html
 
Ranch Hand
Posts: 1865
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you for using my exams.
The latest version of the exam contains new questions in addition to all of the questions from the older exams. To encourage people to use the lastest version, the home page now contains only two links: Latest Exam, and Deprecated Exams. The Latest Exam link will take you to the August 1 version of the exam. The Deprecated Exams page contains links to the three older versions.
I would like to thank Aaron Drielick for his suggestion.
 
Dan Chisholm
Ranch Hand
Posts: 1865
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Maria,
If you want to understand exactly what is happening in that question, then just move the print statement so that it prints the result of each iteration.

When you work through a problem like this on an exam, start by setting up a table of values for the variables. In this case, the variables are a, b, c, d, f. The initial values are a, z, A, Z, N.


Each time you pass throught the loop, start a new row in the table. The last row is the correct answer.
 
Ranch Hand
Posts: 192
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Dan,
why is it possible to catch (Exception e) without a try clause?

class Level1Exception extends Exception {}
class Level2Exception extends Level1Exception {}
class Level3Exception extends Level2Exception {}
class Purple {
public static void main(String args[]) {
char a = 'a';
char b = 'z';
char c = 'A';
char d = 'Z';
char f = 'N';
for (int i = 0; i < 5; i++) {
try { //try clause for catch (Level1Exception e)
try { //try clause for catch (Level2Exception e)
switch (i) {
case 0: throw new Level1Exception();
case 1: throw new Level2Exception();
case 2: throw new Level3Exception();
case 3: break;
default: throw new Exception();
}
a++;
} //End of Level2Exception
//-> now catch Level2Exception
catch (Level2Exception e) {b--;}
finally{c++;}
} //End of
//Level1Exception -> now catch Level1Exception
catch (Level1Exception e) { d--;}
catch (Exception e) {} // WHERE IS TRY- //CLAUSE FOR EXCEPTION?
finally {f++;}
System.out.println ( a+","+c+","+d+","+f+" ");
}
System.out.println("End of loop");
}
}
 
Ranch Hand
Posts: 2120
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It is possible to have more than one catch for the same try. Hoewever the first ones must be more specific (subclasses of) than the last ones, or the compiler will complain.
 
Life just hasn't been the same since the volcano erupted and now the air is full of tiny ads.
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic