004-007-007
Array Length and Search
Easy
Problem Description
Array Length and Search
Learning Objective: Understand how to get the number of elements using the length property and search for a specific value using linear search
Overview
Display the number of city names stored in a string array and use linear search to check whether specified city names exist in the array.
Specifications
- Initialize a string array
citieswith{"Tokyo", "Paris", "London", "New York", "Sydney"} - Print the number of elements in the array
- Search for
"London"using linear search; if found, print its index - Search for
"Berlin"using linear search; if not found, print a message
Output Format
Number of cities: 5
London found at index: 2
Berlin not found
Ready to Try Running Code?
Log in to access the code editor and execute your solutions for this problem.
Don't have an account?
