40 likes | 152 Views
Working with Strings. Characters in a String can be identified by their index #. The first character in a String has index # 0. You need to know the following String methods:. Examples…. String coin = “Nickel”; Demo…. Assignments. ( Rush ) Prompt the user to enter a word.
E N D
Working with Strings • Characters in a String can be identified by their index #. • The first character in a String has index # 0. • You need to know the following String methods:
Examples… String coin = “Nickel”; Demo…
Assignments • (Rush) Prompt the user to enter a word. • If the word is “Neil,” then ask the user to enter a letter. If the letter is a or b, display “Peart.” If it’s another letter, display “Xanadu.” • If the word is “Geddy,” then ask the user to enter a number. If the number is odd and divisible by 9, display “Lee.” If the number is negative or equals 2012, display “YYZ.” 2. (Middle) Prompt the user to enter their middle name. • If the 1st letter is a vowel, display “Vowel”, otherwise, “consonant” • If there are more than 8 letters in the name, display “long”, if between 5 and 8 (inclusive), display “medium”, otherwise, display “short.” • Display whether the # of letters in the name is even or odd. Also, if it’s even, display whether or not it is divisible by 4. If it’s odd, display whether or not it is divisible by 5. • If the letter ‘a’ is in the name, display the first index # it was found at (example: “The letter a was found at index #3”) If it is not found, then say “The letter a was not found.” • If the first and last letters in the name are the same, display “same,” otherwise “different” • If the 2nd letter and the 2nd-to-last letter are both k, display “YES”