• 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

Problem in output and mock tests?

 
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,

I was going through some of the programs. The following two program's output caught me confused.


1)


The answer is:
0 0 3 0.

I could not understand why does it print 3 at the 2nd index.


2)

Answer:
It does not compile.

But if we replace Boolean by string it complies. Why we cant sort a boolean array?


About quote the source:
I am sorry, I dont remember the exact source. I have been solving from miscellaneous sources on the internet and I put all my doubts in a word file as and when I encounter them. Henceforth, I will take the responsibility of making a note of the source too. (Its unlikely to get the real questions though )



MOCK TESTS:

I had previously also posted queries regarding mock tests. I got the following link as a reference http://faq.javaranch.com/java/ScjpMockTests.

Can someone tell me precisely which mock exams (that are free and available online) map with the objectives of SCJP 5?

I have purchased Javabeat's 350 mock questions. Can someone tell me how much does it map with the SCJP 5 objectives?

I would appreciate if some one could thoroughly guide me as after reading K&B, which mock exams should be practiced before appearing for SCJP 5.0?

Thanks All for your time.

Regards
[ August 10, 2008: Message edited by: Badal Chowdhary ]
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Badal Chowdhary,
Welcome to JavaRanch.

A couple tips:

1.) Anytime you post code examples to a testing forum, we require that you include a valid source.
See:
Quote Your Sources for more information.
You can add a source to this post by clicking on the icon in the top post of this thread.

2.) Whenever you post more than 1 or 2 lines of code to JavaRanch, be sure to wrap your code in a set of UBB CODE tags.
Doing so will preserve your indentation making the code much easier to read.
If your code is easier to read, you stand a much better chance of having someone knowledgeable read it and answer your question for you.
 
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Badal!

It is indeed hard to trace the program just by looking at it, but I tried in
in code anyway.

#1


And here's the trace

1st iteration
i=1
arr[i]=0
your array is now arr{1, 0, 3, 4}

2nd iteration
i=0
arr[i] = 0
your array is now arr{0, 0, 3, 4}

3rd iteration
i=3
arr[i] = 0
your array is now arr{0, 0, 3, 0}

4th iteration
i=0
arr[i] = 0
your array is now arr{0, 0, 3, 0}

I hope this helps
[ August 09, 2008: Message edited by: Quirino Gervacio ]
 
Quirino Gervacio
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi again Badal!

#2


Arrays are also objects whether the elements of your arrays are primitives. In your problem, notice that this is valid.

but in the API of Arrays helper class, there is no Array.sort(Object), only Arrays.sort(Object[]), and then some..

I hope this helps.
[ August 09, 2008: Message edited by: Quirino Gervacio ]
 
George Gates
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Quirino,

Thanks for answering the questions.

I still have some doubts.

#1)
Can you tell how the values of 'i' changes in the 4 iterations?

#2)
If arr is a boolean array, how is it possible to say


Shouldn't it be something like this...


Thanks again
 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Badal Chowdhary:
Hi Quirino,

Thanks for answering the questions.

I still have some doubts.

#1)
Can you tell how the values of 'i' changes in the 4 iterations?

#2)
If arr is a boolean array, how is it possible to say


Shouldn't it be something like this...


Thanks again



Dear Badal,

#1) the fourth iteration i is assigned with a value = 0 beecause the fourth element is 0 due to the third iteration. Third iteration:

array[3] = 0 which is the fourth element as array is 0-based indexed

Result in: array[0] = 0 (first element)

#2) It simply does NOT compile as Arrays class does not have a method to sort an array of boolean. It DOES have methods to sort arrays of other primitive types. Read Java API for more info

Hope that helps
[ August 10, 2008: Message edited by: Steve Ng ]
 
Quirino Gervacio
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

is valid

Notice when you perform a dot operation in arr, you'll be able to use the methods of the Object class.

Not

Because arr is not an array of object.

Also, just like Steve posted, there is no Arrays.sort(boolean[])
The API is also your best friend. :-)

I hope this helps
[ August 10, 2008: Message edited by: Quirino Gervacio ]
 
George Gates
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, I get it now.
Thanks
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic