Question
IN JAVA(JGRASP) Write a program that asks the user to enter the name of his or her favorite city. Use a String variable to store
IN JAVA(JGRASP)
Write a program that asks the user to enter the name of his or her favorite city. Use a String variable to store the input. The program should display the following:
? The number of characters in the city name
? The name of the city in all uppercase letters
? The name of the city in all lowercase letters
? The first character in the name of the city
*********************************************************************************************
This is my code so far:
14 public class City 15 { 16 17 public static void main(String[] args) 18 { 19 //Variables 20 String city; 21 Scanner keyboard = new Scanner (System.in); 22 //Display information 23 System.out.print(" Enter the name of your favorite City: "); 24 City = keyboard.nextLine (); 25 System.out.println("Number of characters: " + city.length ()); 26 System.out.println(City.toUpperCase()); 27 System.out.println(City.toLowerCase()); 28 System.out.println(City.charAt(0)); 29 30 }//End main 31 32 }//End class
****************************************************************************************
Here are the following errors I received:
City.java:21: error: cannot find symbol Scanner keyboard = new Scanner (System.in); ^ symbol: class Scanner location: class City
City.java:21: error: cannot find symbol Scanner keyboard = new Scanner (System.in); ^ symbol: class Scanner location: class City
City.java:24: error: cannot find symbol City = keyboard.nextLine (); ^ symbol: variable City location: class City
City.java:26: error: cannot find symbol System.out.println(City.toUpperCase()); ^ symbol: method toUpperCase() location: class City
City.java:27: error: cannot find symbol System.out.println(City.toLowerCase()); ^ symbol: method toLowerCase() location: class City
City.java:28: error: cannot find symbol System.out.println(City.charAt(0)); ^ symbol: method charAt(int) location: class City 6 errors
***************************************************************************
WHAT DO I NEED TO DO IN ORDER TO GET THIS PARTICULAR CODE TO WORK CORRECTLY?
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started