• 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
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

Sun's Sample Q&A. Java 1.1 Question 5.

 
Ranch Hand
Posts: 111
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
At the Sun certification site (see link in mock exam list) there are two sets of sample questions. The first set of 7 questions is for Java 1.2. The second set of six questions is for Java 1.1.
The answer to the following question is given as B.
5. Which correctly creates an array of five empty Strings (select all that apply)?
A. String a [ ] = new String [5]; for (int i = 0; i < 5; a[i++] = "");
B. String a [ ] = {"", "", "", "", ""};
C. String a [5];
D. String [ ] a = new String [5]; for (int i = 0; i < 5; a[i++] = null);
E. String [5] a;
However, I believe A would work as well.
 
Desperado
Posts: 3226
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I agree with you
 
Ranch Hand
Posts: 1467
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok. I didn't check the answer in Sun's site. It takes a lot of time to get to sun's site. Since you had checked already, I am moving this thread to 'Mock Exam Errata' forum. See whose qstn is coming to out Errata Forum.
regds
maha anna
[This message has been edited by maha anna (edited April 10, 2000).]
 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Answer A does not work. I replaced "" with "a" so the results would be easier to see. To me, this seems like a pretty rotten question.
public class Test{
public static void main (String args[]){
String a [ ] = new String [5];
for (int i = 0; i < 5; a[i++] = "a")
{
System.out.println(a[i]);
}
String b[] = {"a","a","a","a","a"};
for (int i =0; i < 5; i++)
{
System.out.println(b[i]);
}
}
}
Result
C:\WINDOWS\Desktop>java Test
null
null
null
null
null
a
a
a
a
a
 
Betty Reynolds
Ranch Hand
Posts: 111
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Don,
I don't see your point. The results that I get show that A is no different from B. Run this code:

The result is:

(The editor for this post appears to be removing the 5 blank lines after each "Empty Array X" line above, but the code actually does produce 5 blanks lines after each.)

[This message has been edited by Betty Reynolds (edited April 16, 2000).]
 
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Don- the problem is this loop:
<code><pre>for (int i = 0; i < 5; a[i++] = "a")
{
System.out.println(a);
}</pre></code>
The statement <code>a[i++] = "a"</code> is executed [I]after
the print statement in each case, at the end of each loop iteration. Try this instead:
<code><pre>for (int i = 0; i < 5; i++)
{
a[i] = "a";
System.out.println(a[i]);
}</pre></code>
 
Betty Reynolds
Ranch Hand
Posts: 111
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
4/21/2000
I think I should point out that there were at least two sites that had exam objectives and only one of them had the error.
This one, which has the I/O objectives, was the one in error.
This was probably always correct.
The good news is that Sun appears to have corrected the problem. Hopefully, the mock exam authors will do the same.

[This message has been edited by Betty Reynolds (edited April 21, 2000).]
 
Hug your destiny! And hug this tiny ad:
New web page for Paul's Rocket Mass Heaters movies
https://coderanch.com/t/785239/web-page-Paul-Rocket-Mass
reply
    Bookmark Topic Watch Topic
  • New Topic