forked from codehouseindia/Java-Programs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreverseString.java
More file actions
31 lines (30 loc) · 966 Bytes
/
Copy pathreverseString.java
File metadata and controls
31 lines (30 loc) · 966 Bytes
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
29
30
31
#https://www.facebook.com/KrishAnshuAvinash/posts/1298368930512766
#subscfibed by Avinash Upadhyay
import java.util.*;
public class Example {
public static void main(String[] args) {
String name = "Avinash Upadhyay";
System.out.println("The full name is: " + name);
System.out.print("Initials with surname is: ");
int len = name.length();
name = name.trim();
String str1 = "";
for (int i = 0; i < len; i++) {
char ch = name.charAt(i);
if (ch != ' ') {
str1 = str1 + ch;
} else {
System.out.print(Character.toUpperCase(str1.charAt(0)) + ". ");
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);
}
}