answer.
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
Nataly_w
2 months 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:
amid [951]2 months 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:

The task requires creating a program that will prompt users to input three cities named Atlanta, Chicago, and Los Angeles (which are to be sorted in ascending alphabetical order).

Thus, we're going to develop the code using a programming language called JAVA (JUST ANOTHER VIRTUAL ACCELERATOR).

We chose Java for this task because it is capable of loading, validating, and executing code on either single or multiple servers.

The code can be found in the attached document/file. Please take a look at it.

Download doc
You might be interested in
A company moves a popular website to a new web host. Which of the following will change as a result?
8_murik_8 [964]
The root name server.
3 0
2 months ago
A network administrator has received the IPv6 prefix 2001:DB8::/48 for subnetting. Assuming the administrator does not subnet in
8_murik_8 [964]

Answer:

subnets=65536

Explanation:

As per our knowledge,

--> the address's interface ID portion begins at 64

--> there exists a 48 bit network prefix

therefore,

the bits available for subnets are = 64-48=  16

thus, by utilizing 16 bits, the number of subnets can be calculated as = 2^16 = 65535

6 0
2 months ago
One example of how psychological research can be used to control harmful behavior would be __________. A. fooling individuals th
Harlamova29_29 [1022]

Psychological research can be misused for harmful reasons like deceiving people through emotions, using propaganda to shift beliefs, or media manipulation.

However, it can also be beneficial, which is the intent of the question. Clearly, from the options presented, only (D) enhancing communication and relationships represents a positive application of psychological research.

8 0
2 months ago
Read 2 more answers
Access to sensitive or restricted information is controlled describes which of the key communications and information systems pr
maria [1035]
Answer C: Security. It is crucial that communication and information systems maintain security to safeguard sensitive data from unauthorized access. Certain types of information, such as voices and data traffic, are of high sensitivity and must be adequately protected according to data privacy regulations.
4 0
1 month ago
Other questions:
  • Why is computer called versatile machine?
    7·1 answer
  • Strlen("seven"); what is the output?
    14·1 answer
  • Knowledge flows from the information that has been generated. Which of the following does not necessarily flow from information
    15·1 answer
  • In Section 8.5.4, we described a situation in which we prevent deadlock by ensuring that all locks are acquired in a certain ord
    11·1 answer
  • 7.7 LAB: Using a while loop countdown Write a program that takes in an integer in the range 10 to 100 as input. Your program sho
    11·1 answer
  • James is an intern in a film production company. On his first day, James’ boss, Monica, tells him, “Before anything else, let me
    9·1 answer
  • The engineering firm you work for is submitting a proposal to create an amphitheater at a state park. Proposals must be submitte
    15·1 answer
  • The function below takes two numeric parameters. The first parameter specifies the number of hours a person worked and the secon
    13·1 answer
  • Write the pseudocode that determines the change to be dispensed from a vending machine. An item in the machine can cost between
    9·1 answer
  • Ellen is expecting to get a 3% raise next year. She enters .03 in cell D2 so that she can predict her monthly income for the nex
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!