import java.util.*;
public class convert_case
{
public static void main(String[]args)
{
Scanner sc = new Scanner(System.in);
System.out.println("enter a string");
String str= sc.nextLine();
String str1="";
int l=str.length();
char chr;
char chr1;
for(int i=0;i<l;i++)
{
chr =str.charAt(i);
if (chr>='a'&&chr<='z')
{
chr1=Character.toUpperCase(chr);
str1=str1+ chr1;
}
else if(chr>='A'&&chr<='Z')
{
chr1=Character.toLowerCase(chr);
str1=str1+ chr1;
}
else
str1=str1+chr;
}
System.out.println(str1);
}
}
Sunday, 18 October 2020
Alter the case of the characters in a string.
Output:
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment