• 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

Khalid's Exam

 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
h ifriends,
its me again. actually I've to give the exam on 22nd of this month. thats why this continuous list of questions.
this time 2 questions from khalid's mock exam
1. we want ot print the last argument given on command line. alternatively, exit gracefully if there is nop argument.
code is here :
public static void main(String a[]) {
try {
System.out.println(a[a.length - 1]);
}
catch {NullPointerException e) {}
}

the answer saya that this code will not do the work. and an uncaught ArrayIndexOutOfBoundsException will occur if no argument is there.
is it correct ?
2. what is the result of following method invocation ?
gfx.drawRect(5,5,10,10);
a. Rectangle will have a total width of 5 pixels.
b. Rectangle will have a total width of 6 pixels.
c. Rectangle will have a total width of 10 pixels.
d. Rectangle will have a total width of 11 pixels.

answer given is (D)
rectangle will have a total width of 11 pixels.
is it correct ?
please help me.
thanks in advance.

Ravi..
 
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
With regards to your first question. If there are no arguments then the length is 0 and therefore length - 1 is -1. THis obviously would lead to an ArrayIndexOutOfBoundsException
 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

As far as your second question, answer D is correct. Normal rectangle width and height is width+1 and height+1. If it is a Filled rectangle then its width and height would bw width and height only.
Anil
 
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi ravi .. best of luck for ur exams ..
first que will give a runtime exception ..
manal...
 
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

Originally posted by anya:

As far as your second question, answer D is correct. Normal rectangle width and height is width+1 and height+1. If it is a Filled rectangle then its width and height would bw width and height only.
Anil


1)
Acc. to the method ,The left and right edges of the rectangle are at x and x + width. The top and bottom edges are at y and y + height.So the width of rectangle must be the mentioned width in methodHow is it possible to have width+1 as width of rectangle.Pl. correct me where i am wrong.
Thanks!
 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Interestingly, the method spec for fillRect says it's coord's are
x, x+width-1, and y, y+height-1. And goes on to say this fills in arectangle of width width and height height.
So, I guess coord's of x, x+width, y, y+height should imply width width+1, and height height+1??
Something is not adding up??(Pun unintended:-) )
------------------
Romba Chinna Thambi
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic