메뉴로 건너 뛰기 내용으로 건너 뛰기
커뮤니티 COMMUNITY
제목 [Jason Lee] AP Computer Science A
Manual Transversal 26
작성자 you*** 등록일 2020-08-16 오전 1:25:02
Hello!

I have a specific question about the if statement in the manual transversal loop.

For chapter 08 files 9 and 10, why do the if statements need to be negated?
Foe instance, why can't it be 
if ( fromIndex > from.length)
instead of 
if ( ! ( fromIndex < from.length))?

I tried to program it the way I thought it would work (by not using the negate method) and it gave me an error but I can't figure out why...

Also, for file 10 (arrayFit2), even if the target is still 'to', why does it need to be coded in the "opposite" way of file 09?
(Like creating the index variable as fromIndex instead of toIndex)

Thank you.
2020-08-18 오후 6:45:36

 

 Hello!
 
I have a specific question about the if statement in the manual transversal loop.
 
For chapter 08 files 9 and 10, why do the if statements need to be negated?
Foe instance, why can't it be 
if ( fromIndex > from.length)
instead of 
if ( ! ( fromIndex < from.length))?
======================================================
good question; they don't. I was trying to accentuate the fact that it was the negation of the 'continue' condition.
if you want to drop the !, you should do fromIndex >= from.length, because negation of > is <= not < 
(an elusive fact that most people run into..)
 
======================================================
I tried to program it the way I thought it would work (by not using the negate method) and it gave me an error but I can't figure out why...
 
Also, for file 10 (arrayFit2), even if the target is still 'to', why does it need to be coded in the "opposite" way of file 09?
(Like creating the index variable as fromIndex instead of toIndex)
=======================================================
not really sure what this question exactly is.. but index names can be anything you want.
just make sure you remember which index is used for which structure.
if you're referring to whether which one should use for-loop traversal instead of manual traversal, 
again it's up to you, just pick the one that needs complete traversal (i.e., easier to implement)
 
=======================================================
 
Thank you.
Top