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
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));
}
}
}
Comments
Leave a comment