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]
4 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]4 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
The field on which records are sorted is called the composite primary key.A. TrueB. False
Gemiola [76]

Answer: TRUE

Explanation: Composite is simply used to refer to the existence of more than one event or pattern. The composite primary key as related to database management query refers to the synergy or combination of more than one field or column of a specified table which is used in sorting or accurate identification of a record. When attributes are combined, that is more than one, it assists in narrowing down the returned records such that records which are close and exclusive to the options specified are returned. Usually, the more the number of columns which makes uo the case mpoaite keys, the more unique and well sorted our returned output is.

4 0
4 years ago
Which pane displays commands that change relative to the activity taking place in the presentation window's main work area?
LuckyWell [14K]
This is the task mangier panel or i guess as they are calling it the task panel.
you can access this with control, alt, delete.
7 0
3 years ago
How many websites are mobile friendly?
777dan777 [17]

Answer:

Almost 80 percent of websites are mobile friendly

Explanation:

7 0
4 years ago
Please help will give brainliest
ludmilkaskok [199]

Answer:

waterfall- google search

Explanation:

5 0
3 years ago
____________________ memory is the ability to add RAM without shutting down the computer or operating system.
Liula [17]

Answer:

Hot-add

Explanation:

The computer system is a electronic device that is used to perform computational task on input data for a pre-dertermined result. The components of the computer is divided into hardware and software components.

The hardware components are the physical parts of the computer system, while the software component are the instructions that runs the system.

The RAM is a physical component that provides memory for running current activities on the monitor screen. When it is removed or faulty, the screen goes blank. To add more RAM memory to the system while the system is on, activate the hot-add memory settings.

4 0
3 years ago
Other questions:
  • What event in the 1970s contributed to the current
    6·2 answers
  • What Intel socket recommends the use of a liquid cooling system?
    9·1 answer
  • 5. RAM IS YOUR SYSTEM’S-
    14·2 answers
  • To use the AutoCalculate area, select the range of cells containing the numbers for a calculation you want to verify and then pr
    7·1 answer
  • Tim is trying to explain to his aunt how her computer works, but she does not understand what a CPU does. Which description will
    11·1 answer
  • How do i delete peoples comments
    14·2 answers
  • Which of the following can technology NOT do?
    12·1 answer
  • 1. What are the main uses for Protein in the body?
    13·2 answers
  • someone please do this for and send a screeshot or picture please its really important for my examsss :D​
    9·1 answer
  • What will happend when I got a BSOD in Windows?
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!