Tuesday, 29 May 2018

Java program to change case in String



Sample Program:-


 public class SampleProgram {  
      public static void main(String[] args) {  
           String s = "inSeRt";  
           char ar[] = s.toCharArray();  
           for (int i = 0; i < ar.length; i++) {  
                if (ar[i] >= 65 && ar[i] <= 90) { // convert upperCase to lowerCase  
                     ar[i] += 32;  
                } else if (ar[i] >= 97 && ar[i] <= 122) { // convert lowerCase to  
                                                                       // upperCase.  
                     ar[i] -= 32;  
                }  
           }  
           System.out.println(new String(ar));  
      }  
 }  

Output:-


INsErT  

Enjoy Coding.

No comments:

Post a Comment