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 is bug in computer?​
Anton [14]

Answer:

<h2>A bug in a computer is refered to as a "computer virus" its where certain things on the computer or apps on it aren't working like they were designed to. </h2>

Explanation:

<h2>Hope this helps:)!</h2>
6 0
2 years ago
Namecoin is an alternative blockchain technology that is used to implement decentralized version of Routing Banking System.A. Tr
vova2212 [387]

Answer:

False

Explanation:

Namecoin is a type of crypto currency which was originally pronged from Bitcoin software. It is coded in the fashion of Bitcoin with the same algorithm as well. Hence it is not a blockchain technology that is used to implement decentralized version of Routing Banking System. Namecoin can store data within its own blockchain transaction database.

4 0
3 years ago
4. Which of the following root keys contains the data for a system’s non-user-specific configurations? a. HKEY_LOCAL_MACHINE b.
seropon [69]

Answer:

The system’s non-user-specific configurations are stored in the HKEY_LO-

CAL_MACHINE root key of the Registry.

Explanation:

6 0
3 years ago
What are the 5 general terms of the fair use rule
Andrews [41]

the purpose and character of your use.

the nature of the copyrighted work.

the amount and substantiality of the portion taken, and.

the effect of the use upon the potential market

In its most general sense, a fair use is any copying of copyrighted material done for a limited and “transformative” purpose, such as to comment upon, criticize, or parody a copyrighted work. Such uses can be done without permission from the copyright owner

the nature of the copyrighted work; the amount and substantiality of the portion used in relation to the copyrighted work as a whole; and. the effect of the use upon the potential market for or value of the copyrighted work

uwu hope dis halpz!

5 0
3 years ago
Anyone wanna join my giggl?
Leni [432]

Answer:

whats a giggl

Explanation:

7 0
3 years ago
Read 2 more answers
Other questions:
  • What mass of nh3 can be made from 35g of n2?
    14·1 answer
  • If you implement a Wireless LAN (WLAN) to support connectivity for laptops in the Workstation Domain, which domain does WLAN fal
    5·1 answer
  • Select the correct answer.
    15·1 answer
  • What is the first thing you should do when troubleshooting a computer problem
    5·2 answers
  • The World Wide Web is full of unstructured data. Search engines like Google, Bing and Yahoo have been doing a good job of allowi
    5·1 answer
  • Computers help eliminate the repetitiveness of manual tasks. How can this benefit you in your overall career?
    9·2 answers
  • I need help with this line of code:
    5·1 answer
  • Https://www.blooket.com/play?id=300932<br> please
    8·2 answers
  • A ……………………………is used to verify the identity of a website and is issued to the owner of the website by an independent and recogni
    7·2 answers
  • What are basic types of touch screen
    15·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!