Answered step by step
Verified Expert Solution
Question
1 Approved Answer
In Java, write a program that prompts the user to enter four cities and displays them in ascending order. Here is my code but it
In Java, write a program that prompts the user to enter four cities and
displays them in ascending order.
Here is my code but it keeps coming out wrong:
package chapterex;
import java.util.Scanner;
public class ChapterEx
public static void mainString args
Scanner input new ScannerSystemin;
System.out.printEnter the first city: ;
String c input.nextLine;
System.out.printEnter the second city: ;
String c input.nextLine;
System.out.printEnter the third city: ;
String c input.nextLine;
System.out.printEnter the fourth city: ;
String c input.nextLine;
String firstC c;
if ccompareTofirstC
firstC c;
if ccompareTofirstC
firstC c;
if ccompareTofirstC
firstC c;
String thirdC c;
if ccompareTothirdC
thirdC c;
if ccompareTothirdC
thirdC c;
if ccompareTothirdC
String secondC ;
if cequalsfirstC && cequalsthirdC
secondC c;
if cequalsfirstC && cequalsthirdC
secondC c;
if cequalsfirstC && cequalsthirdC
secondC c;
if cequalsfirstC && cequalsthirdC
secondC c;
String fourthC ;
if ccompareTofourthC
firstC c;
if ccompareTofourthC
firstC c;
if ccompareTofourthC
firstC c;
System.out.printlnThe three cities in alphabetical order are firstC secondC thirdC fourthC;
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