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 the major benefit Smartphones and tablet computers have had on social media?
Naddika [18.5K]

Answer:

c

Explanation:

The biggest advantage of smartphones and tablets is that they increased the mobility. This allowed users to access the social media platforms whenever they want. The users can login to their accounts even they are travelling by bus or walking around. This was not possible back in the days where people mostly use desktop computers.

8 0
2 years ago
Given the following adjacency matrix, what is the approximate rank vector after one iteration of the power iteration method (use
ValentinkaMS [17]

Note: The matrix referred to in the question is: M = \left[\begin{array}{ccc}1/2&1/3&0\\1/2&1/3&0\\0&1/3&1\end{array}\right]

Answer:

a) [5/18, 5/18, 4/9]'

Explanation:

The adjacency matrix is  M = \left[\begin{array}{ccc}1/2&1/3&0\\1/2&1/3&0\\0&1/3&1\end{array}\right]

To start the power iteration, let us start with an initial non zero approximation,

X_o = \left[\begin{array}{ccc}1\\1\\1\end{array}\right]

To get the rank vector for the first Iteration:

X_1 = MX_0

X_1 =  \left[\begin{array}{ccc}1/2&1/3&0\\1/2&1/3&0\\0&1/3&1\end{array}\right]\left[\begin{array}{ccc}1\\1\\1\end{array}\right] \\\\X_1 = \left[\begin{array}{ccc}5/6\\5/6\\4/3\end{array}\right]\\

Multiplying the above matrix by 1/3

X_1 = \left[\begin{array}{ccc}5/18\\5/18\\4/9\end{array}\right]

8 0
3 years ago
I plugged my headphones into my computer, but the sound still came out of the speakers. help!
VARVARA [1.3K]

If you mean speakers. You should remove them or if you mean the speakers in the PC. Perhaps you put the headphones in the wrong one. Theres usually too one in the front and the other one in the back of the desktop.





Hope this helps.


Regards. Shaggy


Enjoy your music!

3 0
2 years ago
Read 2 more answers
Which of the following is NOT an advantage of owning a car?
AnnyKZ [126]

Smaller down and monthly payments than leasing a car

Option A.

<u>Explanation:</u>

If you lease a car, then the amount of money that a person has to pay in the form of monthly payments and installments is less when compared to when a person owns a car.

When you own a car, the monthly payment made is more than the monthly payments compared to when the car has to be leased. This is the disadvantage of owning a car, that the payment is more to be made.

8 0
3 years ago
For this step, submit your work in the programming environment by running your code, checking your code for a score. The score y
34kurt

A sample HTML code that contains headers, paragraph tags, hyperlinks is

  • <h1> This is a header </h1>
  • <h2> This is a subtitle heading </h2>
  • <p> This is a paragraph </p>
  • <a href=”www.brainly.com”> Brainly Website </a>

<h3>What is HTML?</h3>

This is the building block of a website and is an acronym that means Hypertext Markup Language.

The HTML code that can be used to add a sample image is: "<img src="pic_Brainly.jpeg" alt="Brainly" width="500" height="333">

The src code means the specific location of the external resource

The width and height show how tall and wide the image would be.

The alt shows the alternative information for the image that can be seen when a person hovers over the image on the website.

Read more about HTML and CSS here:

brainly.com/question/24051672

#SPJ1

3 0
2 years ago
Other questions:
  • Which is a feature of a strong thesis statement? A) It presents only the facts. B) It is open-ended. C) It answers the central q
    15·1 answer
  • What is the purpose for adding images and graphics to a web page?
    5·1 answer
  • Technology offers a variety of rich opportunities available to teachers and students. According to Inan and Lowther (2010), ther
    6·1 answer
  • The lightbulb transfers electricity energy into light what is one type of energy that is also generated that is not a desired af
    14·1 answer
  • which of these describe raw data?check all of the boxes that apply A) what a person buys B) where a person lives C) data that ha
    9·1 answer
  • A rocket always rotates about its___?
    9·2 answers
  • What form of communication are they using​
    6·1 answer
  • What are four differences between tablets and smartphones?
    6·2 answers
  • Binary is best interpreted by a computer because ​
    12·2 answers
  • Does anyone know how to write this right? This is for a coding class and I’m super confused on it.
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!