Page 1 of 1

Some Simple Written Questions

PostPosted: Thu Apr 05, 2007 5:08 pm
by The3point14
This is found on the cis 0506-03 test:

17) Which of the following would replace <#1> so the output is true?

int a = Integer.MAX_VALUE;
a++;
System.out.println(a == <#1>);

the answer is both, Integer.MIN_VALUE, and Math.abs(a);

I understand the MIN_VALUE half of the answer, but how does the absolute value work?

PostPosted: Thu Apr 05, 2007 5:11 pm
by Quelloquialism
Integer.MAX_VALUE + 1 = Integer.MIN_VALUE due to integer overflow.

Math.abs(Integer.MIN_VALUE) = -Integer.MIN_VALUE = Integer.MAX_VALUE + 1 = Integer.MIN_VALUE all over again. Absolute value overflows the integer on MIN_VALUE.

PostPosted: Thu Apr 05, 2007 5:27 pm
by The3point14
Ah I understand, thanks. Hopefully in the next week I will have a few more questions that I don't know how to do for you to solve Nathan, as well as anyone else that can help :).

PostPosted: Thu Apr 05, 2007 7:55 pm
by MistaPotta
Gotta love the odometer effect!

PostPosted: Fri Apr 06, 2007 3:56 pm
by The3point14
Also I am missing page 3 in the 2006 UIL District 1 test.

Thanks ^_^