icon picker
nato

traverse parallel arrays, charAt, character data type, string position, string length

about


remember that each character in a string has a position number starting at 0 and finishing at 1 less than the length of the string

key idea: charAt() function

"Computer".charAt(2) would produce the character at position 2
the charAt() function returns a char value, not a String
'A' is a character value, "A" is a String value

PRIMM steps


PREDICT-RUN

Read the PREDICT-RUN code
Share with a partner what you think will be displayed by the code, try to give reasons for what you see.

INVESTIGATE

add code to display the missing letters for the rest of the word

H
E
L
L
O

MODIFY

copy the code and edit it to display the word in reverse
O
L
L
E
H

MAKE

uncomment the loop code in the MAKE section and run the program
it should display as follows:

Alpha
Bravo
..
Yankee
Zulu

add code using the charAt() function to display as shown below

A is for Alpha
B is for Bravo
..
Y is for Yankee
Z is for Zulu

challenge: how many words

count the number of words in the NATO alphabet that have an even number of characters
an even number will have a remainder of 0 when divided by 2, but use mod to find out

challenge: shortest and longest words

what is the longest NATO word, what is the shortest NATO word?
use the string length functions and the findMax and findMin algorithms
can you get the results using a single loop rather then 2 loops?
use the first array element as the initial value for both max and min

Want to print your doc?
This is not the way.
Try clicking the ⋯ next to your doc name or using a keyboard shortcut (
CtrlP
) instead.