[NTLUG:Discuss] Java/Linux versus school teacher.
steve
sjbaker1 at airmail.net
Mon Mar 19 13:10:38 CDT 2007
Robert Citek wrote:
> What implementation and version of Java are they using on Windows? What
> version of Windows? What implementation and version of Java are you
> using on Linux? What distro and version of Linux?
I believe they are using WinXP and the 'Eclipse' IDE at school
- I think they have JRE 1.5.xxx because there are some built-in
classes that aren't on my Linux version. Here at home we have
SuSE 9.3 and JRE version "1.4.2_11". 'javac' doesn't seem to
have a 'report the version number' option?!?
> You may be right about the Java question. But I'm trying to imagine the
> next few steps. If you are right, how are you going to present your
> results to the teacher? What course of action would you like the
> teacher to take?
I think he needs to change the test for the next bunch of kids he
gives it to.
As it happens, there is another error (which seems bloody obvious
to me) - so I need to talk to him anyway:
Q21) For the following code segment, you may assume that array
arr1 contains elements arr1[0], arr1[1],....,arr1[N-1] where
N = arr1.length
int count = 0 ;
for ( int i = 0 ; i < N ; i++ )
if ( arr1 [ i ] != 0 )
{
arr1[count] = arr1[i] ;
count++ ;
}
int[] arr2 = new int [ count ] ;
for ( int i = 0 ; i < count ; i++ )
arr2[i] = arr1[i] ;
If array arr1 initiall contains the elements 0,6,0,4,0,0,2 in
this order, what will arr2 contain after execution of the code
segment?
a) 6,4,2
b) 0,0,0,0,6,4,2
c) 6,4,2,4,0,0,2
d) 0,6,0,4,0,0,2
e) 6,4,2,0,0,0,0
I believe the answer must be (a) - and indeed that's what running
this under Linux does. But the official answer is (c) !!!
That's bizarre. 'count' is initialised to zero and is only
incremented when a non-zero number is found in 'arr1' - so
count can't possibly be bigger than 3. Hence in the 'new'
of the arr2 array, there can be no more than three elements
in the array. We don't even have to think about wierd off-by-one
issues or anything. The output array can't have more than
three elements - so (a) is the answer!
I spend a significant fraction of my life correcting QUESTIONS
in physics, math and computing tests...it's really getting on
my nerves!
Ack!
More information about the Discuss
mailing list