The moose likes Mock Exam Errata and the fly likes Sun's Sample Q&A.  Java 1.1 Question 5. Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Professional Certification » Mock Exam Errata
Reply Bookmark "Sun Watch "Sun New topic
Author

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

Betty Reynolds
Ranch Hand

Joined: Feb 16, 2000
Posts: 111
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.
Tony Alicea
Desperado
Sheriff

Joined: Jan 30, 2000
Posts: 3215
I agree with you


Tony Alicea
Senior Java Web Application Developer, SCPJ2, SCWCD
maha anna
Ranch Hand

Joined: Jan 31, 2000
Posts: 1467
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).]
Don Zur
Greenhorn

Joined: Apr 16, 2000
Posts: 4
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

Joined: Feb 16, 2000
Posts: 111
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).]
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18652
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>

"I'm not back." - Bill Harding, Twister
Betty Reynolds
Ranch Hand

Joined: Feb 16, 2000
Posts: 111
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).]
 
 
subject: Sun's Sample Q&A. Java 1.1 Question 5.
 
Threads others viewed
array of objects..
Interface Set's get() method>>>>
Sample Questions from Sun
sarga mockexam
Sun sample exam - Item 6
developer file tools