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
OlgaM077 [116]
3 years ago
15

Write a Comparator that compares String objects by the number of words they contain. Consider any nonwhitespace string of charac

ters to be a word. For example, "hello" comes before "I see", which comes before "You can do it"
Computers and Technology
1 answer:
Readme [11.4K]3 years ago
8 0

Answer:

import java.util.Scanner;

public class num12 {

   public static void main(String[] args) {

       Scanner in = new Scanner(System.in);

       System.out.println("Enter the first String");

       String word1 = in.nextLine();

       System.out.println("Enter the second String");

       String word2 = in.nextLine();

       System.out.println("Enter the third String");

       String word3 = in.nextLine();

       //Remove all white spaces

        String cword1 = word1.replace(" ","");

       String cword2 = word2.replace(" ","");

       String cword3 = word3.replace(" ","");

       //Comparing the string by their lengths

       if(cword1.length()>cword2.length()&&cword1.length()>cword3.length()){

           System.out.println(word1+" Is the longest");

       }

       else if(cword2.length()>cword1.length()&&cword2.length()>cword3.length()){

           System.out.println(word2+" Is the longest");

       }

       else{

           System.out.println(cword3+" Is the longest");

       }

   }

}

Explanation:

Using Java Programming Language

Use the Scanner Class to obtain the String values from the user

Save them in different variables

Use the replace() method in java to remove white space from any of the string entered

Using if and else statements compare the lengths of the strings (word.length()) returns the length of the word.

Print out the word that is longest

NOTE I have compared three Strings, comparing two would have been more straigth forward

You might be interested in
What happens if part of an ftp message is not delivered to the destination?
Oliga [24]

The message is lost when an FTP message is not delivered to its destination because FTP doesn't use a reliable delivery method.

<h3>What is FTP?</h3>

FTP is an abbreviation for file transfer protocol and it can be defined as a type of server that's designed and developed to store and provide files for download, as well as sharing between two or more users on an active computer network.

Generally, the message is lost when an FTP message is not delivered to its destination because FTP doesn't use a reliable delivery method.

Read more on FTP here: brainly.com/question/20602197

#SPJ12

4 0
2 years ago
How do you create a logo on Adobe illustrator
artcher [175]
Idk idk idk idk if dub
7 0
3 years ago
Which subexpression will be solved first in the given statement?
Crazy boy [7]

Answer:

If you dont buy terraria than im going to make mrbeast buy it for you

Explanation:

reeeeeeeeeeeeeeeeeeeee

4 0
4 years ago
How is technology used in the voting process?
Semmy [17]
Each person has a electronic chip-enabled ID card, which lets them vote on the internet. The ID card is put into the card reader that is connected the computer. :)
7 0
3 years ago
A software or hardware that checks information coming from the Internet and depending on the applied configuration settings eith
photoshop1234 [79]

Answer:

1. Firewall.

2. Router.

3. Proxy.

4. SMTP, 25.

Explanation:

1. A firewall is a network security protocol that monitors and controls inbound and outbound traffic based on set aside security rules.

Generally, a firewall is used to control access to a computer or network, as it creates a barrier between a computer or a network and the internet in order to protect against unauthorized access. It is a security system pre-installed on most computers to essentially inspect data being transmitted to or from a computer.

Furthermore, firewalls are typically bidirectional, it checks all sent and received data and only allow authorized traffic through.

2. A router can be defined as a network device that is designed typically for forwarding data packets between two or more networks based on a well-defined routing protocol.

A routing protocol refers to a set of defined rules or algorithms used by routers to determine the communication paths unto which data should be exchanged between the source router and destination or host device.

Additionally, in order for packets to be sent to a remote destination, these three parameters must be configured on a host.

I. Default gateway.

II. IP address.

III. Subnet mask.

3. A proxy can be defined as a computer network service designed to avail end users (clients) the ability to connect indirectly to other network services. For example, a reverse proxy is a type of server that is placed right in front of other servers such as a web server and it forwards or routes the user's (client) requests to those servers sitting behind it. When properly configured, reverse proxy helps to ensure security, reliability and performance of a network.

4. A spam filter can be defined as a software program designed to process all incoming electronic messages (e-mails) and prevents any unsolicited or unwanted mail (spam) from entering the inbox of a client.

Generally, a spam filter uses SMTP with port number 25 to carry out its services.

SMTP is an acronym for Simple Mail Transfer Protocol and it uses the standard port number of 25 to provide clients with requested services.

3 0
3 years ago
Other questions:
  • Suppose your friend, who is a small business owner, wants to computerize her business functions such as accounting, payroll, and
    7·1 answer
  • A _________ is a copy of one or more files (or entire storage devices) that is made in case the originals become lost or damaged
    5·1 answer
  • Given positive integer num_insects, write a while loop that prints that number doubled up to, but without exceeding 100. Follow
    8·1 answer
  • At the beginning of this month, the balance of Reed's checking account was $692.35. So far this month, he has received a paychec
    13·2 answers
  • You need to access the registry on your windows 10 computer how do you do this
    9·1 answer
  • The ________ is an area where you can position fields to use for filtering the PivotTable and thereby enabling you to display a
    11·1 answer
  • Grace whistles while tickling Camille with a feather. Eventually, Camille starts to squirm and giggle every time Grace whistles,
    10·1 answer
  • How is a microkernel architecture different from a monolithic architecture?
    5·1 answer
  • What is the critical path?
    15·1 answer
  • Write the algorithm and draw a flowchart to display the greatest number among any two different numbers....
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!