Free CoreJava Programs Source codes | Examples | Video Tutorials Download

Tuesday, January 20, 2009

Change Case Of Alphabet Program

import java.io.BufferedReader;
import java.io.InputStreamReader;

/**
* To change case of alphabet from upper to lower and vice-versa
* (assume a single character input)
*/
public class Changecase
{
/**
* change case of given alphabet and displays it
* @throws Exception
*/
public static void changeCase() throws Exception
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));

System.out.println("Enter any alphabet : ");
String str=br.readLine();

if(str.length()!=1)
System.out.println(str + " Is Invalid Input!!!");
else
{
int no=str.charAt(0);
if(no>=65 && no<=90) no+=32; else if(no>=97 && no<=122)
no-=32;
else
{
System.out.println("Error : Invalid Input!!!");
return;
}
System.out.println("Changed case of " + str + " is " + ((char)no));

}

}

/**
* execution begin from here
* @param arg command line argument
*/
public static void main(String[] arg)
{
try
{
changeCase();
}
catch(Exception e)
{
e.printStackTrace();
}
}
}

No comments:

Post a Comment

Followers