change case - Coder's point

Saturday, March 16, 2019

change case

 import java.util.*;  
 import java.io.*;  
 class string2  
 {  
   String str;  
   void change_case()  
   {   
     int i;  
     String temp="";  
     char ch;         
     int c;  
     temp=temp+Character.toUpperCase(str.charAt(0));  
     for(i=1;i<str.length();i++)  
     {  
       if(str.charAt(i)==' '|| str.charAt(i)=='.')  
       {  
         ch=str.charAt(i+1);  
         temp=temp+" "+Character.toUpperCase(ch);  
         i++;   
       }  
       else  
       {  
         temp=temp+str.charAt(i);  
       }  
     }  
     System.out.println(temp);  
   }  
   public static void main()  
   {  
     Scanner in = new Scanner(System.in);  
     string2 obj=new string2();  
     System.out.println("Enter a string in lowercase");  
     obj.str=in.nextLine();  
     obj.change_case();  
   }  
 }  
OUTPUT:
Enter a string in lowercase
lets go for a trip to dubai
Lets Go For A Trip To Dubai

No comments:

Post a Comment