Converting Lowercase to Uppercase 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 lowercase");
String str = sc.nextLine();
char s[]=str.toCharArray();
for(int i=0;i<s.length;i++)
{
if(s[i]>='a' && s[i]<='b')
{
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 Uppercase is");
for(int i=0;i<s.length;i++)
{
System.out.print(s[i]);
}
}
}
Input :-
Enter the word in lowercase
hello
Output :-
word in Uppercase is
HELLO
Comments
Post a Comment