A program to reverse a string and change first character case to lower case and last to lower case. ex: if input is Java 2 Career then output should be Reerac 2 Avaj.

Posted by
Code:

 class reverseNChangeCaseString  
 {  
   public static void main(String a[])  
   {  
     String str="Java 2 Career";  
     String arr[]=str.split(" ");  
     System.out.print("Output:");  
     for(int i=arr.length-1;i>=0;i--)  
     {  
       char temp[]=arr[i].toCharArray();  
       for(int j=temp.length-1;j>=0;j--)  
       {  
         if(j==temp.length-1)  
         {  
         char upper=Character.toUpperCase(temp[j]);  
         System.out.print(upper);  
         }  
         else if(j==0)  
         {  
         char lower=Character.toLowerCase(temp[j]);  
         System.out.print(lower);  
         }  
         else  
         System.out.print(temp[j]);  
       }  
         System.out.print(" ");  
     }  
   }  
 }  

Output:

 

 

 

Leave a Reply