-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupper_case.java
More file actions
35 lines (30 loc) · 938 Bytes
/
upper_case.java
File metadata and controls
35 lines (30 loc) · 938 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
32
33
34
35
import java.util.*;
public class upper_case{
//this function will convert all the first letter to upper case
public static String touppercase(String s){
StringBuilder n=new StringBuilder("");
int l=s.length();
for(int i=0;i<l;i++){
if(i==0){
char u=Character.toUpperCase(s.charAt(i));
n.append(u);
}
else if(s.charAt(i-1)==' '){
{
char u=Character.toUpperCase(s.charAt(i));
n.append(u);
}
}
else{
n.append(s.charAt(i));
}
}
return n.toString();
}
public static void main(String args[]){
Scanner sc=new Scanner(System.in);
System.out.print("enter a string : ");
String s=sc.nextLine();
System.out.println(touppercase(s));
}
}