Write a Comparator that compares String objects by the number of words they contain. Consider any nonwhitespace string of characters to be a word. For example, "hello" comes before "I see", which comes before "You can do it"

Answers

Answer 1
Answer:

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


Related Questions

Communicators do not have an ethical responsibility to share information that other people require to make informed decisions.True/False
____ means saving data in computer memory.
1. What is the difference between computer organization and computer architecture? 2. What is an ISA? 3. What is the importance of the Principle of Equivalence of Hardware and Software? 4. Name the three basic components of every computer. 5. To what power of 10 does the prefix giga- refer? What is the (approximate) equivalent power of 2? 6. To what power of 10 does the prefix micro- refer? What is the (approximate) equivalent power of 2?
Create an application named ArithmeticMethods whose main() method holds two integer variables. Assign values to the variables. In turn, pass each value to methods named displayNumberPlus10(), displayNumberPlus100(), and displayNumberPlus1000(). Create each method to perform the task its name implies. Save the application as ArithmeticMethods.java.
/* Q1. (20 points)Create a stored procedure sp_Q1 that takes two country names like 'Japan' or 'USA'as two inputs and returns two independent sets of rows: (1) all suppliers in the input countries, and (2) products supplied by these suppliers. The returned suppliers should contain SupplierID, CompanyName, Phone, and Country. The returned products require their ProductID, ProductName, UnitPrice, SupplierID, and must sorted by SupplierID.You should include 'go' to indicate the end of script that creates the procedure and you must include a simple testing script to call your sp_Q1 using 'UK' and 'Canada' as its two inputs\.\**For your reference only: A sample solution shows this procedure can be created in11 to 13 lines of code. Depending on logic and implementation or coding style, yoursolution could be shorter or longer\.\*/

One advantage of the Second generation of programming language is that it is machine dependent. True or False

Answers

Answer:

I THINK FALSE

Explanation:

Discuss the relationship of culture and trends?

Answers

A good thesis would be something like “Modern culture is heavily influenced by mainstream trends” and just building on it.

A teacher at your school is using her district issued laptop to create spreadsheets for her part-time job as a bookkeeper. Which standard, if any, is this teacher violating?

Answers

The teacher is violating the Standard 1.2 in the education section.

What did the Standard 1.2 states?

The standard states that any educator shall not knowingly misappropriate or use monies, personnel, property, or equipment committed to his or her charger for personal gain or advantage.

Hence, because of this, the teacher has violated the Standard 1.2 in the education section.

Read more about Standard 1.2

brainly.com/question/17277092

#SPJ2

Answer:

The teacher is most likely violating the District Use Policy.

Regarding computer protection, quarantining is defined as ________. Select one: A. placing a found virus in a secure area on the hard drive B. deleting an infected file C. repairing an infected file D. updating your antivirus software

Answers

Answer:

A. placing a found virus in a secure area on the hard drive

Explanation:

When a file is defected in a computer, quarantining is applied to prevent other parts of the computer. The infected file is isolated and if you let your antivirus software, it can delete the infected file.

A cybersecurity analyst is currently investigating a server outage. The analyst has discovered the following value was entered for the username: 0xbfff601a. Which of the following attacks may be occurring?(A) Buffer overflow attack
(B) Man-in-the-middle attack
(C) Smurf attack
(D) Format string attack
(E) Denial of service attack

Answers

Answer:D)Format string attack

Explanation:

Format string attack is the type of attack that causes to change the application functioning .This attack access the memory of the string library. It occurs while the submission of the string as input and then gets tested due to application command.

Other options are incorrect because these are the attacks that don't happens in the application for the alteration of the flow. Thus, the correct option is option(D).

What are the differences betweenCONS, LIST, and APPEND?

Answers

Answer:

These all are constructors.

CONS

(CONS A B)

makes a pair like this:   (A . B)  

In other words, A is the CAR of the pair; B is the CDR of the pair.

For  example:

(CONS 4 5) ==> (4 . 5)

(CONS 4 '(5 6)) ==> (4 5 6)

[The pair (4 . (5 6)) is the same thing as (4 5 6)].

APPEND  

(APPEND A B)

makes a new list by replacing the final nil in A with the list B. A and  

B must be proper lists.

For example:

(APPEND '(4) '(5 6)) ==> (4 5 6)

This takes any amount of number and put in this order

LIST  

In this ,it will return a list whose elements are value of arguments in the order as it appeared in the LIST.It can take any amount of parameters

For example,

(LIST 4) ==> (4)

(LIST 4 5) ==> (4 5)

(LIST 4 5 '(6 7)) ==> (4 5 (6 7))

(LIST (+ 5 6)(* 5 6)) ==> (8 9)