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

  1. Initialize a string array cities with {"Tokyo", "Paris", "London", "New York", "Sydney"}
  2. Print the number of elements in the array
  3. Search for "London" using linear search; if found, print its index
  4. 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?