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
Mary works for a multimedia firm, and she spends long hours on a desktop computer. Recently, she expired back pain and visited h
Sindrei [870]

To stand as she works.

5 0
2 years ago
What types of roles are there as a webmaster?
Nuetrik [128]
<span> PHP, ASP, and Javascript. They handle the technical aspects </span>
6 0
3 years ago
Read 2 more answers
Which of the following statements is false? A.The concepts of icons, menus and windows were originally developed by Xerox PARC.
Fudgin [204]

Answer:

(b) Windows is an open source operating system (<em>This is not correct</em>)

Explanation:

Option a is <em>correct</em> because Xerox PARC(Palo Alto Research Center), which is a subsidiary of the Xerox corporation, has been greatly responsible for invention and development in modern computing devices. Some of these developments are in Ethernet and graphical user interface (making use of menus, icons e.t.c).

Option b is <em>not correct</em> because Windows Operating system is not an open source operating system. Open source OS means users can interact with the driving code of the OS and make modifications. Windows does not support this feature. Operating systems that are open source include Linux and OpenSolaris.

Option c is <em>correct</em>. An operating system has two main components - the kernel and the user interface. The core component of an operating system is the Kernel as it interacts directly with the hardware and manages system resources. The user interface on the other hand allows users to interact with the kernel of the operating system using texts and/or graphics as commands.

Option d is <em>correct</em>. Linux operating system is an open source OS. Therefore, the source code is made available to the public for examination and modification.

8 0
3 years ago
Starting in 2024 under a new law, all new smartphones sold in the eu must have….
Inga [223]

Answer:

USB type C cables.

Explanation:

3 0
2 years ago
Simplify (6x+6)+(-3-4x) please hurry!!!!!
Ilia_Sergeevich [38]

Answer:

2x + 3

Explanation:

8 0
3 years ago
Other questions:
  • Disk scheduling algorithms in operating systems consider only seek distances, because Select one: a. modern disks do not disclos
    13·1 answer
  • Which string method counts the number of characters in a string?
    5·1 answer
  • Is a network traffic management device used to connect different network segments together?
    9·1 answer
  • NEED HELP NOW 25 POINTS!!!!!!
    15·2 answers
  • A corporation needs an operating system that allows the various teams in its office to network and collaborate on projects. Whic
    10·1 answer
  • Name three types of hard drives, along with its speed and size.
    8·1 answer
  • Scott is an aspiring software developer. During an interview for a new job, his prospective employer asks what kind of program h
    12·1 answer
  • The ____ attribute can be used only with input boxes that store text. Group of answer choices type pattern required value
    9·1 answer
  • What is a simulation?
    5·2 answers
  • What is the purpose of the Zoom dialog box? to put the selected range in ascending order in a query to put the selected range in
    13·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!