Write a program to take a String as input then display the first letter of each word.
Example:
Enter a String
JAPAN is Best
JiB
import java.util.*;
class App {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
System.out.println("Enter a String: ");
String string = in.nextLine();
int length = string.length();
System.out.print(string.charAt(0));
for (int i = 0; i < length; i++) {
if (string.charAt(i) == ' ') {
System.out.print(string.charAt(i + 1));
}
}
in.close();
}
}
Comments
Leave a comment