Converting Uppercase to Lowercase using Java
import java.util.*;
class UpperCaseToLowerCase
{
public static void main(String[] args)
{
Scanner sc =new Scanner(System.in);
System.out.println("Enter any Word in uppercase");
String str = sc.nextLine();
char s[]=str.toCharArray();
for(int i=0;i<s.length;i++)
{
if(s[i]>='A' && s[i]<='Z')
{
s[i]=(char)((int)s[i]+32);//60 -90 A-Z
//97-122 a-z
// differnce bwtn upper case and lowecase is 122-90=32
}
}
System.out.println("Word in lowercase is");
for(int i=0;i<s.length;i++)
{
System.out.print(s[i]);
}
}
}
Input :-
Enter any Word in uppercase :- HELLO WORLD
Output :-
Word in lowercase is :-hello world
Comments
Post a Comment