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
kakasveta [241]
2 years ago
10

Write a program named SortWords that includes a method named SortAndDisplayWords that accepts any number of words, sorts them in

alphabetical order, and displays the sorted words separated by spaces. Write a Main() to test this funciton. The SortAndDisplayWords method will be tested with one, two, five, and ten words
Computers and Technology
1 answer:
sp2606 [1]2 years ago
3 0

Answer:

Following are the program in the C# Programming language.

//header

using System;

//define class

public class SortWords

{//define function

 public static void Display_Words(string[] word)

 {//set string type variable

   string a;

   //set the for loop for swapping the words

   for (int i = 0; i < word.Length; i++)

   {//set the for loop

     for (int j = 0; j < word.Length - 1; j++)

     {

   //set the if conditional statement for compare the string

       if (String.Compare(word[j], word[j + 1], StringComparison.Ordinal) > 0)

       {

       //perform swapping

         a = word[j];

         word[j] = word[j + 1];

         word[j + 1] = a;

       }

     }

   }

   //print message

   Console.WriteLine("Sorted Words: ");

   //set for loop to print the sorted list

   for (int i = 0; i < word.Length; i++)

   {//print space between the sorted characters

     Console.Write(word[i] + " ");

   }

 }

//define the main function

 public static void Main()

 {//print message

   Console.Write("Enter the number of words: ");

   //get input from the user

   int get_size = Convert.ToInt32(Console.ReadLine());

   //set string type array

   string[] word = new string[get_size];

   Console.WriteLine("Enter " + get_size + " words");

   //set for loop to get input in string type array

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

   {

     word[i] = Console.ReadLine();

   }

   //call the function

   Display_Words(word);

 }

}

<u>Output</u>:

Enter the number of words: 5

Enter 5 words

h

e

l

l

o

Sorted Words:

e h l l o

Explanation:

Here, we define a class named "SortWords" and inside the class.

  • Define void type function "Display_words" and pass an string data type array argument "word".
  • Inside the function, we set two for loops to swapping the words and inside it we set the if conditional statement to compare the words then, perform swapping.
  • Set the for loop to print the sorted list

Finally, we define the main function in which we get inputs from the user, firstly we get the number of words then we get the words from the user. then call the function "Display_words".

You might be interested in
Some numbers are formed with closed paths. the digits 0, 4, 6 and 9 each have 1 closed path and 8 has 2. None of the other numbe
postnew [5]

Answer:

def cal(n):

s=0

while n>0:

r=n%10

if(r==0 or r==4 or r==6 or r==9):

s=s+1

elif r==8:

s=s+2

n=n//10

print(s)

n=int(input("enter number:"))  

print(n)

cal(n)

Explanation:

  • Create a function to calculate count of closed path .
  • Create a variable to store count of closed path .
  • While number is positive , extract last digit of n .
  • Reduce number by truncating last digit .
  • Make a function call to compute count of path.
5 0
2 years ago
One form of competition-based pricing is going-rate pricing, inwhich a firm bases its price largely on competitors' prices, with
Kobotan [32]

Answer:

Out of the four options , the option that is most suitable  is

option b. Cost, demand

<u>cost</u> or to <u>demand</u>

Explanation:

Going rate pricing is a form of competition based pricing. This pricing is commonly used for homogeneous products i.e., products with very minute distinction or variation among producers.

This type of pricing is based on setting price on the basis of the prevailing market trends in pricing of goods or services, so, the prices are largely based on the competition in the market rather than considering its own cost and demand.

8 0
2 years ago
Choose the correct function to convert the user’s response to the number 3.5. &gt;&gt;&gt; answer = input("How much does the sam
FromTheMoon [43]

Answer:

The answer to the given question is given bellow in the explanation section:

Explanation:

<p>This is python code</p>

<p>In python when you enter input into the input function as given:</p>

<code> answer = input("How much does the sample weigh in grams? ") </code>

I will be taken as string.

So I have to convert this string to number format here the given data is float value i-e 3.5

so let convert it. using float function.

<code> answer = float (input("How much does the sample weigh in grams? ") )  </code>

6 0
1 year ago
Read 2 more answers
Exponentiation Is a/an operater?​
garik1379 [7]

Answer:

Yes it is

Hope this helps

5 0
1 year ago
In this exercise you will debug the code which has been provided in the starter file. The code is intended to take two strings,
vampirchik [111]

Answer:

Here is the corrected program:

import java.util.Scanner; //to accept input from user

public class 02_14_Activity_one { //class name

    public static void main(String[] args) { //start of main method

    Scanner scan = new Scanner(System.in); //creates Scanner class object

  System.out.println("Enter first string"); //prompts user to enter first string

          String s1 = scan.nextLine(); //reads input string from user

  System.out.println("Enter second string"); //prompts user to enter second string

          String s2 = scan.nextLine(); //reads second input string from user

    System.out.println("Enter number of letters from each word"); //enter n

          int n = scan.nextInt(); //reads value of integer n from user

          System.out.println(s1.substring(0,n) + s2.substring(s2.length() - n ));

         } } //uses substring method to print a string made up of the first n letters of s1 and the last n letters of s2.

Explanation:

The errors were:

1.

Scanner scan = Scanner(System.in);

Here new keyword is missing to create object scan of Scanner class.

Corrected statement:

 Scanner scan = new Scanner(System.in);

2.

String s1 = nextLine();  

Here object scan is missing to call nextLine() method of class Scanner

Corrected statement:

String s1 = scan.nextLine();

3.

String s2 = Scanner.nextLine();

Here class is used instead of its object scan to access the method nextLine

Corrected statement:

String s2 = scan.nextLine();

4.

String n = scan.nextLine();

Here n is of type String but n is a whole number so it should be of type int. Also the method nextInt will be used to scan and accept an integer value

Corrected statement:

int n = scan.nextInt();

5.

System.out.println(s1.substring(1,n-1) + s2.substring(s1.length()-n));

This statement is also not correct

Corrected statement:

System.out.println(s1.substring(0,n) + s2.substring(s2.length() - n ));

This works as follows:

s1.substring(0,n) uses substring method to return a new string that is a substring of this s1. The substring begins at the 0th index of s1 and extends to the character at index n.

s2.substring(s2.length() - n ) uses substring method to return a new string that is a substring of this s2. The substring then uses length() method to get the length of s2 and subtracts integer n from it and thus returns the last n characters of s2.

The screenshot of program along with its output is attached.

7 0
2 years ago
Other questions:
  • Which statement best describes how the rapid prototyping model works?a) Developers create prototypes to show stakeholders how va
    11·2 answers
  • A search box does all of the following EXCEPT ________.
    12·2 answers
  • Consider a simple application level protocol built on top of udp that allows a client to retrieve a file from a remote server re
    15·2 answers
  • What critical issue in symmetric and asymmetric encryption is resolved by using a hybrid method like diffie-hellman?
    5·2 answers
  • If a street has a central lane bordered by solid yellow and broken yellow lines, you ________________.
    6·1 answer
  • In response to a recent outbreak of computer viruses, Babbage Industries, a large technology company, installs computer virus pr
    7·2 answers
  • Initialize the list short_names with strings 'Gus', 'Bob', and 'Zoe'. Sample output for the givenprogram:Gus Bob Zoeshort_names
    13·1 answer
  • A device has an IP address of 10.1.10.186 and a subnet mask of 255.255.255.0. What is true about the network on which this devic
    9·1 answer
  • What types of messages flow across an SDN controller’s northbound and southbound APIs? Who is the recipient of these messages se
    15·1 answer
  • +10 POINTS AND BRAINLIEST!! HELP ME PLEASE!!~~~
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!