-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathintials.java
28 lines (28 loc) · 874 Bytes
/
intials.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import java.util.*;
public class intials {
public static void main(String[] args) {
String name = "Rahul Das";
System.out.println("The full name is: " + name);
System.out.print("Initials with surname is: ");
int len = name.length();//9
name = name.trim();//
String str1 = "";
for (int i = 0; i < len; i++) {
char ch = name.charAt(i);
if (ch != ' ') {
str1 = str1 + ch;//Rahul
} else {
System.out.print(Character.toUpperCase(str1.charAt(0)) + ". ");//R.
str1 = "";
}
}
String str2 = "";
for (int j = 0; j < str1.length(); j++) {
if (j == 0)
str2 = str2 + Character.toUpperCase(str1.charAt(0));
else
str2 = str2 + Character.toLowerCase(str1.charAt(j));
}
System.out.println(str2);
}
}