import java.io.*;
class StrTog
{
public static void main(String arg[])
{
int i;
System.out.println("Enter the String:");
DataInputStream d=new DataInputStream(System.in);
try
{
String str=d.readLine();
char a[]=str.toCharArray();
for(i=0;i<a.length;i++)
{
if((a[i]>='a')&&(a[i]<='z'))
{
a[i]=(char)((int)a[i]-32);
}
}
for(i=1;i<a.length;i++)
{
if((a[i-1]==' ')&&((a[i]>='a')&&(a[i]<='z')))
{
a[i]=(char)((int)a[i]-32);
}
if((a[i-1]!=' ')&&((a[i]>='A')&&(a[i]<='Z')))
{
a[i]=(char)((int)a[i]+32);
}
}
System.out.println("After convert:");
for(i=0;i<a.length;i++)
{
System.out.print(a[i]);
}
}
catch(Exception e)
{
System.out.println(e);
}
}
}
Output:
class StrTog
{
public static void main(String arg[])
{
int i;
System.out.println("Enter the String:");
DataInputStream d=new DataInputStream(System.in);
try
{
String str=d.readLine();
char a[]=str.toCharArray();
for(i=0;i<a.length;i++)
{
if((a[i]>='a')&&(a[i]<='z'))
{
a[i]=(char)((int)a[i]-32);
}
}
for(i=1;i<a.length;i++)
{
if((a[i-1]==' ')&&((a[i]>='a')&&(a[i]<='z')))
{
a[i]=(char)((int)a[i]-32);
}
if((a[i-1]!=' ')&&((a[i]>='A')&&(a[i]<='Z')))
{
a[i]=(char)((int)a[i]+32);
}
}
System.out.println("After convert:");
for(i=0;i<a.length;i++)
{
System.out.print(a[i]);
}
}
catch(Exception e)
{
System.out.println(e);
}
}
}
Output:
No comments:
Post a Comment