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
Tema [17]
3 years ago
7

Write a program that prompts the user for his or her name. Display the number of words and characters in the entered name.

Computers and Technology
1 answer:
Law Incorporation [45]3 years ago
4 0
<h2><u>Answer:</u></h2>

// import the Scanner class to allow for user input

import java.util.Scanner;

// define a class for the program

public class NumOfWordsAndChars {  

   // the main method

   public static void main(String[] args) {

       // create an object of the Scanner class, call it <em>input</em>

       Scanner input = new Scanner(System.in);

      //1. Prompt the user to enter their name

       System.out.println("Please enter your name");

       //using the input object, receive and store the entered

       //name in a string variable called <em>name</em>.

       String name = input.nextLine();

       // declare and initialize to zero, a variable noOfWords

       // that will hold the number of words in the name.

       int noOfWords = 0;

       // 2. Get the number of words.        

       // Check to see if the user actually entered a name.

       // If they did enter a name, use the split() function to break

       // the entered name into its constituent words and store

       // these words in an array variable called <em>words.</em>

<em>        </em>// From the words array, the number of words can be found

       // by simply getting the length of the array using <em>words.length</em>

<em>        </em>// Store the number of words in the variable <em>noOfWords</em>

       if (name != null && !name.isEmpty()){

           String words [] = name.split("\\s+");

           noOfWords = words.length;

       }

       // 3. Get the number of characters.

       // the number of characters in a string is found using the function lenght()

      // store the number of characters in an integer variable, <em>noOfChars</em>

       int noOfChars = name.length();

       // 4. Display the number of words and characters

       System.out.println("No of words: " + noOfWords);

       System.out.println("No of characters: " + noOfChars);

   }                       // End of main method

}                          // End of the class declaration

<h2><u>Explanation</u>:</h2>

The above code has been written in Java.

The code contains comments explaining every part of the code. Please carefully go through the comments in the code.

The source code has also been attached to this reponse. Please download the file and you may run it on your Java enabled local machine.

Note that the split() function in the code receives an argument which is a regular expression representing one or more whitespace characters i.e \\s+.

This means that the string (name) should be split into its constituent words since a word is typically a non-space character in a string.

<em>Hope this helps!</em>

Download java
You might be interested in
Photographs, illustrations, and videos are increasingly created an and viewed in digital formats. True or False​
lutik1710 [3]

Answer:

I think it's True but I don't know sorry if I'm wrong

6 0
3 years ago
Read 2 more answers
Fill in the blanks:In the context of cyber security, social engineering (SE) is a deceptive practice that exploits human _______
lord [1]

Answer:

In the context of cyber security, social engineering (SE) is a deceptive practice that exploits human <u>weaknesses </u>  by inducing victims to interact with a digital device in a way that is not in their best interest. Many of these attacks begin with<u> spam</u> , which is defined as unsolicited messages that are usually sent in massive numbers using electronic mail systems. A spam  <u>filter</u> uses a set of rules to examine email messages and determine which are spam. There are four common types of spam filters.<u> Content  </u>filters examine the content within a message for certain words or phrases commonly used in spam emails.<u> Header</u> filters review the email header for falsified information, such as spoofed IP addresses. <u>Blacklist</u> filters block mail that originates from IP addresses of known spammers. <u>Permission </u>                    filters block or allow mail based on the sender's address. <u>Phishing</u> is an email scam that masquerades as a message from a(n) legitimate company or agency of authority, such as the IRS. <u>Pharming</u> redirects Web site traffic to fraudulent Web sites that distribute malware, collect personal data, sell counterfeit products, and perpetrate other scams. A rogue <u>antivirus </u>                exploit usually begins with a virus warning and an offer to disinfect the infected device. Some software is not exactly malware, but it is a nuisance. A <u>PUA </u>takes up residence on a digital device and seems impossible to disable or remove.

3 0
3 years ago
Suppose you were assigned to develop a logical model of the registration system at a school or college. Would you be better off
BaLLatris [955]

Answer:

top down approach

Explanation:

Top down approach is process of breaking down system into sub-system which helps in formulating the overall system. At the end every sub system can be refined with more details.

While bottom up approach is process of gathering systems to design large complex system.

Top down is better as basic information is present and resources can be utilized effectively without impacting maintennance and operations.

6 0
3 years ago
What is a privacy data breach
kotykmax [81]

Answer: A privacy data breach occurs when personal information is stolen or lost or is collected, used or disclosed without authority. A privacy breach occurs when personal information is stolen or lost or is collected, used or disclosed without authority.

Explanation:

Examples of a  data breach might include:

Loss or theft of hard copy notes, USB drives, computers or mobile devices. an unauthorized person gaining access to your laptop, email account or computer network. sending an email with personal data to the wrong person.

7 0
1 year ago
In which of the following scenarios would you choose to embed versus import data?
Mrrafil [7]

Answer:

B.)You want to maintain connections with external files

Explanation:

These are the options for the question

A.)You do not want to save the original data sources.

B.)You want to maintain connections with external files

C.)You want to reduce file size

Embedding data can be regarded as insertion of objects( embedded object) such as spreadsheet into a word-processor so that it can be edditted.

Data Import can be regarded as ways that give room for uploading of data

from external sources , then combine it with data that is been collected via Analytics.

6 0
3 years ago
Other questions:
  • Which of the following statements about Java Class Libraries is false: a. Java class libraries consist of classes that consist o
    9·1 answer
  • what is a massive online storage that allows for access by any Internet connected device running a web browser and is used for l
    7·1 answer
  • 1.<br> Which of the following is NOT caused by alcohol?
    15·2 answers
  • You can use RWA to demonstrate how to do something special on the web, such as displaying articles found on websites that suppor
    15·1 answer
  • The desktops of computers running the same OS all look the same
    8·1 answer
  • Whats your favorite sport between these options?
    12·2 answers
  • If an interest inventory reveals that you are highly interested in solitary, introverted work, what might be the best type of ca
    9·2 answers
  • In a batch operating system, three jobs are submitted for execution. Each job involves an I/O activity, CPU time and another I/O
    12·1 answer
  • a(n) ___ loop allows you to cycle through an array without specifying the starting and ending points for the loop
    14·1 answer
  • What are the differences between a cursor, insertion point and mouse pointer?​
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!