answer.
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
ella [17]
2 years ago
4

The following program counts the total number of letters in a person's first and last names. The getAndCountNameLetters() method

creates a Scanner, reads a name from the user input, and returns the number of letters. Run the program. Note that the program does not count letters in the last name. The first call to scnr.next() returns the first name, but also reads the last name to make future reads faster. The second call to getAndCountNameLetters() creates a different Scanner, which has nothing left to read. Change the program by passing a Scanner to the getAndCountNameLetters() method. Run the program again. Note that the count now includes the last name.
Computers and Technology
1 answer:
nikdorinn [45]2 years ago
4 0

Answer:

import java.util.Scanner;

public class NameCount

{

public static void main(String[] args) {

    int firstNameCount = 0;

    int lastNameCount = 0;

    Scanner scnr = new Scanner(System.in);

 System.out.print("Enter the person's first and last name: ");

 

 firstNameCount = getAndCountNameLetters(scnr);

 lastNameCount = getAndCountNameLetters(scnr);

 

 System.out.print("The first name has " + firstNameCount + " letters");

 System.out.print("The last name has " + lastNameCount + " letters");

}

public static int getAndCountNameLetters(Scanner scnr) {

    String name = "";

   

    if(scnr.hasNext())

        name = scnr.next();

       

   return name.length();

}

}

Explanation:

Create a method called getAndCountNameLetters that takes one parameter, a Scanner object

Inside the method:

Initialize a variable called name

Read the input and assign it to the name variable

Return the name

Inside the main:

Initialize count variables for first and last name

Get the name from the user

Set the first and last name's count by calling the method getAndCountNameLetters

Print the counts

You might be interested in
The part of the computer that contains the brain, or central processing unit, is also known as the A.monitor B.modem C.keyboard
olga_2 [115]
<span>The part of the computer that contains the brain, or central processing unit is also known as System Unit.Because Cpu plays a vital role and it is the central component in computer.Without Cpu calculations are not performed by computer.It directs the entire computer system to carry out stored program instructions.</span>
5 0
2 years ago
Consider a router that interconnects three subnets: subnet 1, subnet 2, and subnet 3. suppose all of the interfaces in each of t
creativ13 [48]

Answer:

thank God for us you and keep hoping tougher than I thought it would be

4 0
2 years ago
Read 2 more answers
When you use a while loop to compute the product of several values, you should initialize the variables holding the product to _
Allushta [10]

Answer:

b.1

Explanation:

When we are using while loop to compute the product of several values we need to initialize the value holding the product to 1 because when we multiply something with 1 it will give the same number.

If we initialize it with 0 the product will come out to be 0 because  anything multiplied by 0 is 0.

we cannot initialize it with NULL because it is not a pointer.

We need to initialize the number since it contains garbage values so it will give product with that value.

3 0
2 years ago
Kathy is a senior teacher in her school. She is conducting a group discussion between parents and teachers. Her role is to ensur
Fynjy0 [20]
She is the leader of the discussion
3 0
2 years ago
Read 2 more answers
Janice is unsure about her future career path she has grown up on her family farm but she is also interested in medicine Janice
KiRa [710]
Janice can actually used both knowledge as an advantage. She can use her background in farming while learning more about medicine. In such a way, she can have a strong advantage in medicinal farming - like learn ways to create good and effective drugs from plants, etc. 
5 0
2 years ago
Other questions:
  • The spreadsheet below shows the names years in office, and number of terms for five US presidents
    7·2 answers
  • Desmond works in Power, Structural, and Technical Systems. He would most likely be employed by
    5·2 answers
  • You are the IT security administrator for a small corporate network. Samuel Garcia (sgarcia) has been away on vacation and has f
    9·1 answer
  • Remember that it is desirable for good block ciphers that a change in one input bit affects many output bits, a property that is
    9·1 answer
  • Sara is using her personal laptop (which is password protected) at a "hotspot" at a local cafe with wifi access. She is in the m
    7·1 answer
  • Write a program that lets a user enter N and that outputs N! (N factorial, meaning N*(N-1)*(N-2)*..\.\*2*1). Hint: Initialize a
    5·1 answer
  • Write a function that takes a string like 'one five two' and returns the corresponding integer (in this case, 152). A function j
    11·2 answers
  • Which OS function does a CLI fulfill? A User interface B Running applications C Hardware interface D Booting
    8·1 answer
  • Which of these are characteristics of a Python data type? Check all that apply.
    11·1 answer
  • Write an application that accepts up to 20 Strings, or fewer if the user enters the terminating value ZZZ. Store each String in
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!