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
V125BC [204]
3 years ago
10

Write a Java program to count the characters in each word in a given sentence?Examples:Input : geeks for geeksOutput :geeks->

5for->3geeks->5
Computers and Technology
1 answer:
dimulka [17.4K]3 years ago
4 0

Answer:

import java.util.Scanner;

public class Main

{

public static void main(String[] args) {

   

    Scanner in = new Scanner(System.in);

   

    System.out.print("Enter a sentence: ");

    String sentence = in.nextLine();

   

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

   

    for(String s : words)

     System.out.println(s + " -> " + s.length());

}

}

Explanation:

Ask the user to enter a sentence

Get each word in the sentence using split method and put them in words array

Loop through the words. Print each word and number of characters they have  using the length method in required format

You might be interested in
Assume that you have an ArrayList variable named a containing 4 elements, and an object named element that is the correct type t
jonny [76]

Answer:

Option (4) is the correct answer.

Explanation:

In Java programming language ,array collection starts from 0 index location and ends in a size-1 index location. So to access the last elements the user needs to use a[Size-1] statement. so to modify the value of the last location of the array the user needs to use "a[size-1]= element;".

But when the user wants to add some new value to the end of the array list collection then he needs to use the statement--

a.add(element); //where add is a function, element is a value and a is a array list object.

Another option is invalid because--

  • Option 1 is not the correct because "a[3]=element;" modify the value of the 3rd element of the array.
  • Option 2 gives a compile-time error because add functions bracts are not closed.
  • Option 3 gives the error because a[4] gives the location of the 5th element of the array but the above question says that a is defined with 4 elements.
7 0
2 years ago
What field in a TCP segment is used to determine if an arriving data unit exactly matches the data unit sent by the source?
Rina8888 [55]

Answer:

a. Checksum

Explanation:

Based on the information provided within the question it can be said that the field that represents this information is called the Checksum. Like mentioned in the question this refers to a value that represents the amount of bits in a certain transmission message. This is done in order to make sure that the amount of bits that were sent match the amount that were received in order to make sure that no data was lost in transit that would cause high-level errors.

7 0
3 years ago
How has the shift to locally grown produce decreased greenhouse emissions?
Katen [24]

Answer:

How has the shift to locally grown produce decreased greenhouse emissions? 1 Large farms often create greenhouse emissions by poor farming practices. 2 Locally grown produce allows fewer dangerous toxins to seep into the soil and the atmosphere.

3 0
2 years ago
Technician A says that wheel speed sensors are a highly probable cause of illuminated EBC warning lamps. Technician B says that
Blababa [14]

Technician A because

3 0
3 years ago
Fryshta is using the Help window in PowerPoint to learn about inserting Smart Shapes into a presentation. She currently has a He
Rainbow [258]

Answer: Pin

Explanation:

Pin button is the button that is used for sticking or saving the ideas from the windows or web on that very place.This feature helps in reviewing or getting the idea back later anytime from the window as per users need. User use this button for saving any food recipe, steps of any process, guidelines etc.

  • According to the question, Fryshta can use pin button from the help window for sticking or pinning the steps of inserting shapes in her presentation.She can have a look at the steps whenever she want.
8 0
3 years ago
Other questions:
  • Given 3 floating-point numbers. Use a string formatting expression with conversion specifiers to output their average and their
    14·1 answer
  • A hub transmits all incoming messages to all of its ports except the port where the messages came in. A switch usually sends mes
    14·2 answers
  • Who was the 1st person to use the term television
    11·1 answer
  • Topological sort requires only a tiny addition to the DFS algorithms. Exactly one of the following data structures is required t
    9·1 answer
  • Which ipv6 router message is sent via multicast with a scope of link-local with the expectation that all local routers will iden
    5·1 answer
  • Which of the following statements holds true for the term "html"? It refers to a system that connects end users to the Internet.
    10·2 answers
  • A _____ refers to a product or service, such as a technical report, a training session, a piece of hardware, or a segment of sof
    12·2 answers
  • Use the drop-down menus to complete each sentence about the layers of the atmosphere.
    14·2 answers
  • Computers and Technology:
    14·1 answer
  • Var1 = 1<br> var2 = 2<br> var3 = "3"<br> print(var1 + var2 + var3)
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!