-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtoupper.java
More file actions
27 lines (24 loc) · 772 Bytes
/
toupper.java
File metadata and controls
27 lines (24 loc) · 772 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
public class toupper {
public static String upper(String str) {
StringBuilder sb = new StringBuilder("");
sb = sb.append(Character.toUpperCase(str.charAt(0)));
for (int i = 1; i < str.length(); i++) {
if (i < str.length() - 1 && str.charAt(i) == ' ') {
sb.append(str.charAt(i));
i++;
sb = sb.append(Character.toUpperCase(str.charAt(i)));
} else if (str.charAt(i) == ',' && str.charAt(i + 1) != ' ') {
sb.append(str.charAt(i));
i++;
sb.append(Character.toUpperCase(str.charAt(i)));
} else {
sb.append(str.charAt(i));
}
}
return sb.toString();
}
public static void main(String[] args) {
String str = "iam,dhruv lamba";
System.out.println(upper(str));
}
}