Write a program to take a name as input then display the signature as the first letter of each word with dot.
Enter a String
Hubert Blaine Wolfeschlegelsteinhausenbergerdorff Sr
H.B.W.S.
Don't use array and split function
import java.util.*;
class App {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
System.out.println("Enter a String: ");
String inputString = in.nextLine().toUpperCase();
System.out.print(inputString.charAt(0) + ".");
for (int i = 0; i < inputString.length(); i++) {
if (inputString.charAt(i) == ' ') {
System.out.print(inputString.charAt(i + 1) + ".");
}
}
in.close();
}
}
Comments
Leave a comment