import java.util.*;
class App {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
System.out.println("Enter a String: ");
String words[] = in.nextLine().split(" ");
for (int i = 0; i < words.length; i++) {
System.out.print(words[i].toUpperCase().charAt(0) + ".");
}
in.close();
}
}
Do this coding without using array and split
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();
System.out.print(string.toUpperCase().charAt(0) + ".");
for (int i = 0; i < string.length(); i++) {
if (string.charAt(i) == ' ') {
System.out.print(string.toUpperCase().charAt(i + 1) + ".");
}
}
in.close();
}
}
Comments
Leave a comment