Finding Elements Tutorial
From Progzoo
Sometimes you need to process only part of the array. You can start the for at 1 instead of 0. You can have the loop condition as i<x.length-1 rather than i<x.length
Contents |
Print All Items Except the First
[Font]
[Default]
[Show]
[Resize]
[History]
[Profile]
Print All Items Except the Last
Print each item, but do not print last item.
For the array [2, 7, 5, 3] you should print:
2 7 5
[Font]
[Default]
[Show]
[Resize]
[History]
[Profile]
Print each Item and the Next One
Print each item followed by the following item. Don't process the last element.
For the array [2, 7, 5, 3] you should print:
2 7 7 5 5 3
[Font]
[Default]
[Show]
[Resize]
[History]
[Profile]
Print each Item and the One Before and the One After
Print each item, print the one before, the item and the one after. Don't process the first or the last element.
For the array [2, 7, 5, 3] you should print:
2 7 5 7 5 3
[Font]
[Default]
[Show]
[Resize]
[History]
[Profile]
Mark the Duplicates
Print each item (except the last one) followed by the next one. If the next item is the same mark it with *
For the array [2,2,5,3] you should print:
2 2* 2 5 5 3
[Font]
[Default]
[Show]
[Resize]
[History]
[Profile]
