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
Part of the central processing unit
AveGali [126]

Answer:

Explanation:

The arithmetic logic unit (ALU) performs mathematical, logical, and decision operations.  It can be divided into the arithmetic unit (responsible for addition, subtraction, multiplication and division).  And logic unit (responsible for comparing, selecting, matching and merging different data or information).  The power and efficiency of the CPU depends on the design of the ALU.  

Next up is the control unit (CU) which directs all the processor’s operations.  It’s where the CPU reads and interprets requests from memory and transforms them into a series of signals (binary).  Then it sends the operation to various parts of the laptop as instructed.  The CU calls the ALU to perform the necessary calculations.  It also coordinates all input/output devices to transfer or receive instructions.

The main job of the memory unit is to store data or instructions and intermediate results.  It’s divided into primary memory and secondary memory to supply data to other units of the CPU.  It allows the CPU to perform functions requested by programs like the operating system without having to ask RAM.

Another element of the CPU not depicted in the diagram is transistors.  To carry out calculations, binary information (ones and zeros) is stored in these microscopic switches.  They control the flow of electricity depending on whether the switch is ON or OFF.  Signals turn off and on different combinations of transistors to perform calculations.  A very thin silicon chip can contain several hundred million transistors.

8 0
3 years ago
F(x) = -x^3-x<br> Is this function odd?
Crank

Answer:

yes it is odd beacuse 3 is a odd number

6 0
2 years ago
Read 2 more answers
What command utilizes the limpel-ziv (lz77) compression algorithm and achieves a compression ratio of 60-70 percent?
AURORKA [14]

The limpel-ziv (lz77) compression technique is used by the GNU zip (gzip) tool to produce a compression ratio of 60–70%.

<h3>How do methods for data compression function? Describe the LZW algorithm.</h3>

Compression methods lower the amount of memory needed to hold pictures and the number of bytes needed to represent data. Compression improves the amount of data that can be delivered over the internet and enables the storage of more photos on a given media.

Abraham Lempel, Jacob Ziv, and Terry Welch developed the table-based lookup technique known as LZW compression to compress a file into a smaller file. The TIFF image format and the GIF image format are two frequently used file formats that employ LZW compression.

To know more about limpel-ziv (lz77) compression algorithm, Visit:

<u>brainly.com/question/19878993</u>

#SPJ4

4 0
1 year ago
In the game of economics, producers look to technological improvements to increase which of the following?
Vaselesa [24]
They're looking to increase productivity 
7 0
3 years ago
Read 2 more answers
Which part of the computer contains logic circuity which interrupts instructions from a program​
poizon [28]

Answer:

The control unit of the CPU contains circuitry that uses electrical signals to direct the entire computer system to carry out stored program instructions.

Explanation: The control unit does not execute program instructions rather, it directs other parts of the system to do so.

6 0
3 years ago
Other questions:
  • We never need to use a forward declaration when invoking a public subprogram. true or false?
    15·1 answer
  • You are the network administrator for a company with a single Active Directory domain. The corporate office is located in Miami
    5·1 answer
  • An aerophone is an instrument that causes ________ to vibrate, thus creating sound waves.
    11·2 answers
  • Communication of a message between two processes implies which of the following? (A) Synchronization (B) Atomic operation (C) Bl
    11·1 answer
  • Write down the bit pattern in the fraction of value 1/3 assuming a floating point format that uses Binary Coded Decimal (base 10
    10·1 answer
  • Write a calculator program using a switch statement that: a) Prompts the user to enter two numbers b) Prompts the user to select
    6·1 answer
  • Which line of code will eliminate the element “calculator” from an array of supplies?
    13·1 answer
  • Someone please tell me please y my ps4 controller won’t charge:(
    12·2 answers
  • PLZ HELP I AM TIMED!!!!
    11·2 answers
  • What's your fav show?
    12·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!