Pages

Tuesday, 23 April 2013

Java code to change Lowercase letters to Uppercase and vice-versa in a string

Java program to change Lowercase letters to Uppercase and vice-versa in a string.

import java.io.*;
class CaseChange
{
static String n;
static int l;
 public static void main(String args[]) throws IOException
 {
 BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
 System.out.print("Enter a String : ");
 n = br.readLine();
 l = n.length();
 changeCase();
 }
 public static void changeCase()
 {
 char c;
 String b = "";
 for(int i=0;i<l;i++)
 {
  c = n.charAt(i);
  if(c>=65 && c<=90)
  b+=(char)(c+32);
  else
  if(c>=97 && c<=122)
  b+=(char)(c-32);
  else
  b+=c;
 }
 System.out.println("\nOriginal : " +n);
 System.out.println("Changed : " +b);
 }
}

ALGORITHM:-

1. Start

2. Accept a sentence from the user.

3. Extract each character from the sentence.

4. Check whether the character is in uppercase or lowercase.

5. Convert the uppercase letters to lowercase and vice-versa.

6. Don't change special characters.

7. Print the old as well as the new sentence.

8. End.

OUTPUT:-

Java code to change Lowercase letters to Uppercase and vice-versa in a string

Enter a String : ToMaTo

Original : ToMaTo

Changed : tOmAtO

Related Programs:-

Print the Factorial of a number using recursion

Print the possible combination of a string

Generate Fibonacci series using recursion

Find the HCF & LCM of two numbers using recursion

Find the sum of the following series using recursion : 12 + 22 + 32 +.......+ n2

No comments:

Post a Comment

Back to Top