hey everybody! I want to create a program that counts the number of each word in a sentence given by the user. but I dont know how it is. pls help me...

This program asks for your name, you type in your name or whatever you want and press enter, then it will tell you how many characters (including spaces) are in the string.

import java.util.Scanner;
 
 public class YourProgramName
 {
 	public static void main (String [] args)
 	{
 		Scanner keyboard = new Scanner (System.in);	
 			
 		String name;
 		
 		System.out.println ("Enter Your Name");
 		name = keyboard.nextLine();
 		
 		int stringLength = name.length();
 		
 		System.out.println(stringLength);
 	}
 }

thanks for your answer but,I can make a program that counts chars in a sting. I want to calculate how many times each words was written in the string.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.