You will write 2 nested loops in this homework assignment.
mkdir ~/cs170/hw6
cp ~cs170002/share/hw6/*.java ~/cs170/hw6
cd ~/cs170/hw6
|
|
Examples:
|
for ( n = 2; n <= 10000; n++ )
if ( n is a perfect number )
print n;
|
To determine if a number n is perfect, use a loop to compute the sum of its divisors and check if the sum is equal to n
|
|
You should know by now how to compile and run Java programs....
|
Examples:
"aabcd" ( 'a' ≤ 'a' ≤ 'b' ≤ 'c' ≤ 'd' ) "bbbbtxyz" "abcdefghij" |
The following are not "non-decreasing" subsequences:
"acb" ( 'c' > 'b' !!! )
"bhkxij" ( 'x' > 'i' !!! )
|
For example:
String: "abdhktcegkxklmwaabhxbbbc"
------^^^^^----^^^^^----
The first (longest possible) "increasing" subsequence = "abdhkt"
The next (longest possible) "increasing" subsequence = "cegkx"
The next (longest possible) "increasing" subsequence = "klmw"
The next (longest possible) "increasing" subsequence = "aabhx"
The final (longest possible) "increasing" subsequence = "bbbc"
|
|
Hints:
|
|
You should know by now how to compile and run Java programs....
cd ~/cs170/hw6
/home/cs170002/turnin-hw Perfect.java hw6
/home/cs170002/turnin-hw MaxSubseq.java hw6a
|