Converting each alphabet of a string into its opposite case.
Write a program to input a string. Convert each alphabet into its opposite case. Print original and new string.
SOURCE CODE
import java.io.*;
import java.util.*;
public class Conversion
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
System.out.print("Enter a String :");
String str=sc.nextLine();
String st="";
System.out.println("\nOUTPUT");
System.out.println("Original String "+str);
for(int i=0;i<str.length();i++)
{
char ch=str.charAt(i);
if(Character.isUpperCase(ch))
{
st=st+Character.toLowerCase(ch);
}
else if(Character.isLowerCase(ch))
{
st=st+Character.toUpperCase(ch);
}
else
{
st=st+ch;
}
}
System.out.println("Converted String = "+st);
}
}
OUTPUT
If you have any question then leave a comment below I will do my best to answer that question.
Comments
Post a Comment