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
Anna [14]
1 year 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]1 year 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
Translate the following MIPS code to C. Assume that the variables f, g, h, i, and j are assigned to registers $s0, $s1, $s2, $s3
Romashka [77]

Answer:

f = 2 * (&A[0])

See explaination for the details.

Explanation:

The registers $s0, $s1, $s2, $s3, and $s4 have values of the variables f, g, h, i, and j respectively. The register $s6 stores the base address of the array A and the register $s7 stores the base address of the array B. The given MIPS code can be converted into the C code as follows:

The first instruction addi $t0, $s6, 4 adding 4 to the base address of the array A and stores it into the register $t0.

Explanation:

If 4 is added to the base address of the array A, then it becomes the address of the second element of the array A i.e., &A[1] and address of A[1] is stored into the register $t0.

C statement:

$t0 = $s6 + 4

$t0 = &A[1]

The second instruction add $t1, $s6, $0 adding the value of the register $0 i.e., 32 0’s to the base address of the array A and stores the result into the register $t1.

Explanation:

Adding 32 0’s into the base address of the array A does not change the base address. The base address of the array i.e., &A[0] is stored into the register $t1.

C statement:

$t1 = $s6 + $0

$t1 = $s6

$t1 = &A[0]

The third instruction sw $t1, 0($t0) stores the value of the register $t1 into the memory address (0 + $t0).

Explanation:

The register $t0 has the address of the second element of the array A (A[1]) and adding 0 to this address will make it to point to the second element of the array i.e., A[1].

C statement:

($t0 + 0) = A[1]

A[1] = $t1

A[1] = &A[0]

The fourth instruction lw $t0, 0($t0) load the value at the address ($t0 + 0) into the register $t0.

Explanation:

The memory address ($t0 + 0) has the value stored at the address of the second element of the array i.e., A[1] and it is loaded into the register $t0.

C statement:

$t0 = ($t0 + 0)

$t0 = A[1]

$t0 = &A[0]

The fifth instruction add $s0, $t1, $t0 adds the value of the registers $t1 and $t0 and stores the result into the register $s0.

Explanation:

The register $s0 has the value of the variable f. The addition of the values stored in the regsters $t0 and $t1 will be assigned to the variable f.

C statement:

$s0 = $t1 + $t0

$s0 = &A[0] + &A[0]

f = 2 * (&A[0])

The final C code corresponding to the MIPS code will be f = 2 * (&A[0]) or f = 2 * A where A is the base address of the array.

3 0
1 year ago
Se dau lungimile a N cuvinte (0 &lt; N ≤ 5 000), formate din cel puțin un caracter. Să se afișeze lungimea minimă necesară R a u
IceJOKER [234]

Answer:

Explanation:

Clearer rendering reads;

"Give the lengths of N words (0 <N ≤ 5 000), consisting of at least one character. Display the minimum required length R of a line on a page, so that on each line the cumulative length of the words is exactly R (no spaces between them). Words are not allowed to be separated".

6 0
2 years ago
Given three dictionaries, associated with the variables, canadian_capitals, mexican_capitals, and us_capitals, that map province
Nookie1986 [14]

Answer:

The Python code to combine the three dictionaries are is given as follows:

  1. canadian_capital = {
  2.    cash: "SOME VALUES",
  3.    assets: "SOME VALUES"
  4. }
  5. mexican_capital = {
  6.    cash: "SOME VALUES",
  7.    assets: "SOME VALUES"
  8. }
  9. us_capital = {
  10.    cash: "SOME VALUES",
  11.    assets: "SOME VALUES"
  12. }
  13. nafta_capital = {
  14.    canadian: canadian_capital,
  15.    mexican : mexican_capital,
  16.    us: us_capital
  17. }

Explanation:

<u>Line 1 - 14 :</u>

Create three Python dictionaries and name them as <em>canadian_capitals, mexican_capital </em>and<em> us_capitals</em>. Please note a Python dictionaries should be enclosed in curly braces { }.  

We just define two samples of relevant keys (<em>cash </em>and <em>asset</em>) in each of the dictionaries. Python dictionary can map a key to a value.

Since we are not given any capital values from the question,  a dummy string "<em>SOME VALUES</em>" is tentatively set as the value for each of the keys.

In practice, we should replace those dummy strings with the real values of capital. The values can be a number, a string, a list and even a nested dictionary.

<u>Line 16 - 20 : </u>

Create one more Python dictionary and name it as <em>nafta_capital</em>.

Since our aim is to combine the three previous dictionaries (<em>canadian_capitals, mexican_capital </em>and <em>us_capitals</em>) and associate it with <em>nafta_capital</em>, we can define three different keys (<em>canadian, mexican </em>and <em>us</em>) in our dictionary nafta_capital.

As mentioned, a value associated with a key can be a nested dictionary. Hence, we just map <em>canadian_capitals, mexican_capital </em>and <em>us_capitals</em> as the value of the keys (<em>canadian, mexican </em>and<em> us</em>) in dictionary<em> nafta_capital,</em> respectively,

By doing so, we have managed to combine three target dictionaries (<em>canadian_capitals, mexican_capital </em>and <em>us_capitals</em> ) into a single dictionary, <em>nafta_capital</em>.

4 0
1 year ago
To use the Web, each client computer requires a data link layer software package called a Web browser. True False
Luden [163]

Answer:

The answer is "False"

Explanation:

The data link layer is the protocol layer within a program, which controls data movement into a physical wireless connection. This layer is a second layer, that is also known as a collection of communications applications.

  • The server network, in which many clients request, and receive service from a centralized server.
  • This system provides an interface, that enables a user to request server services and view the server returns results, that's why it is wrong.
6 0
1 year ago
Problem 2 - K-Best Values - 30 points Find the k-best (i.e. largest) values in a set of data. Assume you are given a sequence of
masya89 [10]

Answer:

See explaination

Explanation:

/**KBestCounter.java**/

import java.util.ArrayList;

import java.util.List;

import java.util.PriorityQueue;

public class KBestCounter<T extends Comparable<? super T>>

{

PriorityQueue heap;

int k;

public KBestCounter(int k)

{

heap = new PriorityQueue < Integer > ();

this.k=k;

}

//Inserts an element into heap.

//also takes O(log k) worst time to insert an element

//into a heap of size k.

public void count(T x)

{

//Always the heap has not more than k elements

if(heap.size()<k)

{

heap.add(x);

}

//if already has k elements, then compare the new element

//with the minimum element. if the new element is greater than the

//Minimum element, remove the minimum element and insert the new element

//otherwise, don't insert the new element.

else if ( (x.compareTo((T) heap.peek()) > 0 ) && heap.size()==k)

{

heap.remove();

heap.add(x);

}

}

//Returns a list of the k largest elements( in descending order)

public List kbest()

{

List al = new ArrayList();

int heapSize=heap.size();

//runs O(k)

for(int i=0;i<heapSize;i++)

{

al.add(0,heap.poll());

}

//Restoring the the priority queue.

//runs in O(k log k) time

for(int j=0;j<al.size();j++) //repeats k times

{

heap.add(al.get(j)); //takes O(log k) in worst case

}

return al;

}

}

public class TestKBest

{

public static void main(String[] args)

{

int k = 5;

KBestCounter<Integer> counter = new KBestCounter<>(k);

System.out.println("Inserting 1,2,3.");

for(int i = 1; i<=3; i++)

counter.count(i);

System.out.println("5-best should be [3,2,1]: "+counter.kbest());

counter.count(2);

System.out.println("Inserting another 2.");

System.out.println("5-best should be [3,2,2,1]: "+counter.kbest());

System.out.println("Inserting 4..99.");

for (int i = 4; i < 100; i++)

counter.count(i);

System.out.println("5-best should be [99,98,97,96,95]: " + counter.kbest());

System.out.println("Inserting 100, 20, 101.");

counter.count(100);

counter.count(20);

counter.count(101);

System.out.println("5-best should be [101,100,99,98,97]: " + counter.kbest());

}

}

5 0
2 years ago
Other questions:
  • A class car and its subclass bmw each have a method run(), which was written by the developer as part of the class definition. i
    10·1 answer
  • An mp3 takes up about 16 kilobytes of memory per second of music. if you owned a one terabyte hard drive and filled it with only
    15·1 answer
  • Given: an int variable k, an int array current Members that has been declared and initialized, an int variable memberID that has
    11·1 answer
  • You have installed a point-to-point connection using wireless bridges and Omni directional antennas between two buildings. The t
    9·1 answer
  • A U.S. social security number consists of a string of 9 digits, such as "444422333". Assume that input consists of a sequence of
    6·2 answers
  • Database management systems are expected to handle binary relationships but not unary and ternary relationships.'
    7·1 answer
  • Samuel received an email that looked like it came from his bank. The email told him to click a link that opened an official look
    7·1 answer
  • You'd like to change the minimum password length policy in the Default Domain Policy group policy preference (GPO). What's the b
    10·1 answer
  • Which statement is true about the purpose of a work in process constraint?
    15·1 answer
  • In order to avoid slipping in the shop, your footwear should ___________.
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!