EduLearn - Online Education Platform

Welcome to EduLearn!

Start learning today with our wide range of courses taught by industry experts. Gain new skills, advance your career, or explore new interests.

Browse Courses

 

 

 

Here’s a simple Java program that takes a sentence as input and prints the number of letters in each word:

βœ… Java Program: Count Letters in Each Word

import java.util.Scanner;

 

public class WordLengthCounter {

public static void main(String[] args) {

Scanner scanner = new Scanner(System.in);

 

// Input sentence

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

String sentence = scanner.nextLine();

 

// Split the sentence into words using space

String[] words = sentence.split(” “);

 

// Loop through each word and print its length

for (String word : words) {

System.out.println(word + “=” + word.length());

}

}

}

βœ… Sample Input:

hello world java code

βœ… Output:

hello=5

world=5

java=4

code=4

 

. Write a java program that takes a sentence as input and prints numbers of letters in each word

 

input: “hello world java code”

 

output:

hello=5

world=5

java=4

code=4

 

class Find

{

public static void main(String args[])

{

String data=”hello world java code”;

 

String another[]=data.split(” “);{hello–>0

world–>1

java–>2

code–>3}–>another

 

for(String a:another)

{

System.out.println(a+”=”+a.length());//hello=5 world=5 java=4 code=4

}}}

 

 

 

 

Java program for printing an element

Leave a Reply

Your email address will not be published. Required fields are marked *

EduLearn - Online Education Platform

Welcome to EduLearn!

Start learning today with our wide range of courses taught by industry experts. Gain new skills, advance your career, or explore new interests.

Browse Courses

Popular Courses

[Course Image]

Introduction to Programming

Learn the fundamentals of programming with Python in this beginner-friendly course.

12 Hours Beginner
[Course Image]

Data Science Essentials

Master the basics of data analysis, visualization, and machine learning.

20 Hours Intermediate
[Course Image]

Web Development Bootcamp

Build modern websites with HTML, CSS, JavaScript and popular frameworks.

30 Hours Beginner
[Course Image]

Digital Marketing Fundamentals

Learn SEO, social media marketing, email campaigns and analytics.

15 Hours Beginner
Educational Website Footer