1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Anna [14]
3 years ago
8

Write a program that prompts the user to enter three cities and displays them in ascending order. Here is a sample run: Enter th

e first city: Chicago Enter the second city: Los Angeles Enter the third city: Atlanta The three cities in alphabetical order are Atlanta Chicago Los Angeles
Computers and Technology
1 answer:
maria [59]3 years ago
3 0

Answer:

import java.util.Scanner;

public class SortStrings3 {

   public static void main(String args[]){

       Scanner scanner = new Scanner(System.in);

       String str1, str2, str3;

       System.out.print("Enter the first city: ");

       str1 = scanner.nextLine();

       System.out.print("Enter the second city: ");

       str2 = scanner.nextLine();

       System.out.print("Enter the third city: ");

       str3 = scanner.nextLine();

       System.out.print("The three cities in alphabetical order are ");

       if(str1.compareTo(str2) < 0 && str1.compareTo(str3) < 0){

           System.out.print(str1+" ");

           if(str2.compareTo(str3) < 0){

               System.out.print(str2+" ");

               System.out.println(str3);

           }

           else {

               System.out.print(str3+" ");

               System.out.println(str2);

           }

       }

       else if(str2.compareTo(str1) < 0 && str2.compareTo(str3) < 0){

           System.out.print(str2+" ");

           if(str1.compareTo(str3) < 0){

               System.out.print(str1+" ");

               System.out.println(str3);

           }

           else {

               System.out.print(str3+" ");

               System.out.println(str1);

           }

       }

       else{

           System.out.print(str3+" ");

           if(str1.compareTo(str2) < 0){

               System.out.print(str1+" ");

               System.out.println(str2);

           }

           else {

               System.out.print(str2+" ");

               System.out.println(str1);

           }

       }

   }

}

EXPLANATION:

Okay, we are given that a program should be written which will make user to enter three cities namely Atlanta, Chicago and Los Angeles (which should be done in ascending  alphabetical order).

So, we will be writting the code or program with a programming language known as JAVA(JUST ANOTHER VIRTUAL ACCELERATOR).

We will make use of java to write this program because Java can be used in Loading code, verifying codes and executing codes on a single or multiple servers.

The code or program can be seen in the attached file/document. Kindly check it.

Download doc
You might be interested in
It’s just a multiple choice question about emails
cestrela7 [59]
The Answer is : A, B , C .
7 0
3 years ago
Read 2 more answers
How many centimeters are there in 1 meters
konstantin123 [22]
1 meters is = 100 centimeters
8 0
4 years ago
Read 2 more answers
Write a program that inputs two characters first and second, and then prints all non-alphabetic characters starting from second
baherus [9]

Answer:

fbtcft gdfgfffff tvfft gxf

8 0
3 years ago
PLEASE HELP ME!!!!!! ITS FOR 100 POINTS AND BRAINLIEST!!!!!!!! NO ONE EVER WANTS TO ANSWER MY QUESTION!!! I JUST NEED SOMEONE TO
Veronika [31]

Answer: my suggestion is to ask a teacher and do research like look up the best shoe companies and things like that

Explanation:

6 0
3 years ago
If str 1 and str2 are both Strings, which of the following expressions will correctly
Novosadov [1.4K]
Str1==str2 is the answer
3 0
4 years ago
Other questions:
  • Consider the following network: proxy-cache On average there are 35 objects downloaded per second, and the average object size i
    14·1 answer
  • Consider the scheduling algorithm in the Solaris operating system for time-sharing threads.a. What is the time quantum (in milli
    7·1 answer
  • Security measures are sometimes described as a combination of physical, technical, and administrative (PTA) safeguards. Which of
    12·1 answer
  • C++ what is wrong with my equation?
    10·1 answer
  • What is the recommended procedure for disconnecting an external hard drive to avoid losing data?
    15·1 answer
  • Which of the following is an example of fine art? 1. fashion 2. interior design 3. painting 4. product design
    7·2 answers
  • What is the multiple source test
    15·1 answer
  • Create a page using PHP for a business website that will ask the user to enter his or her name into text boxes and will display
    5·1 answer
  • What file name would allow you to easily find and edit your document later in Word Online?
    14·2 answers
  • 1.Discuss the complexities of owning and sharing digital information.
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!