Answer to Question #293856 in Java | JSP | JSF for Helen

Question #293856

Write a program to take a String as input then display the words in one column, number of characters in each word in second column and the first letter of each word in third column with appropriate heading.

For example:

Enter a String

Hello world

Words Length First Letter

Hello 5 H

world 5 w


1
Expert's answer
2022-02-04T14:49:59-0500
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        System.out.println("Enter a String");
        String[] words = in.nextLine().split(" ");
        System.out.println("Words Length First Letter");
        for (int i = 0; i < words.length; i++) {
            System.out.println(words[i] + " " + words[i].length() + " " + words[i].charAt(0));
        }
    }
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS