Sunday, January 1, 2012

Toggle the character in Java

Example



import java.io.*;
public class A14
{
public static void main(String args[])
throws IOException
{


String s="";
String s1="";
char ch,ch1;
int a;
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
s=br.readLine();
a=s.length();
for(int i=0;i<a;i++)
{
ch=s.charAt(i);
if (ch>=97 && ch<=122)
{

s1=s1+(char)((int)ch-32);
}
else if(ch>=65 && ch<=91)
{

s1=s1+(char)((int)ch+32);

}


}
System.out.println(s1);

}
}

No comments:

Post a Comment