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
________ is used to install and update software, backup, and restore mobile devices, wipe employer software and data from device
erastovalidia [21]

Answer: MDM softwares

Explanation:

Here MDM refers to mobile device management software which provides people with the facilities of updating, installing creating backup of various mobile devices within an organisation. Moreover these software's provides tools for proper monitoring and to report their usage across various independent mobile device users. MDM is often used or interconnected with the term BYOD(Bring your own device), whereby employees of an organisation bring their own mobile devices and they are being managed by a MDM software centrally.

8 0
3 years ago
Select the statements below that correctly match the meaning of the letter in the concept of developing SMART goals?
fenix001 [56]

Specific, Measurable, Attainable, Relevant and Timely.

6 0
3 years ago
What is the LER for a rectangular wing with a span of 0.225m and a chord of 0.045m
ch4aika [34]

Calculate LER for a rectangular wing with a span of 0.225m and a chord of 0.045m. The weight of the glider is 0.0500 Newtons. (Note: the wing span is the width of the wing and is measured from wing tip to wing tip, or perpendicular to the fuselage. The wing chord is the length of the wing measured parallel or along the length of the fuselage.)

Answer:

Area of rectangular wing = span × chord = 0.225×0.045= 0.010125m2

LER = Area/weight = 0.010125/0.0500 = 0.2025

4 0
2 years ago
which computer career field enables you to create and design interactive multimedia products and services
dusya [7]
I think its graphic design 
4 0
3 years ago
Nearly all social software systems include a(n) ________, which helps control your information flow.
Alekssandra [29.7K]

Answer:

dashboard

Explanation:

4 0
2 years ago
Read 2 more answers
Other questions:
  • Web storage stores data in the browser in
    5·1 answer
  • Consider the relation Courses(C, T, H, R, S, G), whose attributes can be thought of informally as course (C), teacher (T), hour
    10·1 answer
  • which three objects can be linked or embedded in a word document? A. worksheets, margins, colors B. charts, worksheets, images C
    7·1 answer
  • What does the label display when the user clicks the button? void btnSubmit_Click(object sender, EventArgs e) { int num1 = 3; in
    7·1 answer
  • When entering a expressway using a weave lane you must do what
    7·1 answer
  • 1. What makes discrimination different from harassment? (Don't give me definitions.)
    5·1 answer
  • If you give an actual answer I'll give brainliest​
    13·2 answers
  • Write any one method to delete a table in writer​
    11·1 answer
  • Select the correct answer from each drop-down menu
    7·1 answer
  • Alayna is researching information online to write her essay about the Berlin Wall.
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!