Question: Hello, I need this program to check and array to see if the user input is held within. I did a for loop which I

Hello, I need this program to check and array to see if the user input is held within. I did a for loop which I would think would do what is needed, and i have the return statements in there. but it will not run, what is needed for this to be able to run?

// MichiganCities.java - This program prints a message for invalid cities in Michigan. // Input: Interactive. // Output: Error message or nothing.

import java.util.Scanner;

public class MichiganCities { public static void main(String args[]) throws Exception { // Declare variables. String inCity; // name of city to look up in array. // Initialized array of cities in Michigan. String citiesInMichigan[] = {"Acme", "Albion", "Detroit", "Watervliet", "Coloma", "Saginaw", "Richland", "Glenn", "Midland", "Brooklyn"}; boolean foundIt = false; // Flag variable. int x; // Loop control variable.

// Get user input. Scanner input = new Scanner(System.in); System.out.println("Enter the name of the city: "+(x+1)); inCity = input.nextLine(); // Write your loop here. for (int x = 0; x < citiesInMichigan.length; x++) { if(incity == citiesInMichigan[x]); { foundIt = true; } } System.out.println("city entered is a city in Michigan"); else System.out.println("city entered is not a city in Michigan"); } System.exit(0);

} // End of main() method. } // End of MichiganCities class.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!