20. Write a program to define a method void change(), to initialize a character in uppercase form
and convert into its lowercase form. Print the original character and the new character.
Answers
Explanation:
Take input string ‘st’. Let us take st=CODE
Convert string to char array ‘str’
1st iteration for(i=0;i<str.length;i++) i.e. for(i=0;0<4;i++)
if(str[i]>=’A’ && str[i]<=’Z’) i.e. if(str[0]>=’A’ && str[0]<=’Z’) hence(‘C’>=’A’ && ‘C'<=’Z’) true
str[i]=str[i]+32; i.e. str[0]=str[0]+32; i.e. str[o]=67+32; hence str[0]=99 hence str[0]=’c’
2nd iteration for(i=1;i<str.length;i++) i.e. for(i=1;1<4;i++)
if(str[i]>=’A’ && str[i]<=’Z’) i.e. if(str[1]>=’A’ && str[1]<=’Z’) hence(‘O’>=’A’ && ‘O'<=’Z’) true
str[i]=str[i]+32; i.e. str[1]=str[1]+32; i.e. str[1]= 79+32; hence str[1]=111 hence str[1]=’o’
3rd iteration for(i=2;i<str.length;i++) i.e. for(i=2;2<4;i++)
if(str[i]>=’A’ && str[i]<=’Z’) i.e. if(str[2]>=’A’ && str[2]<=’Z’) hence(‘D’>=’A’ && ‘D'<=’Z’) true
str[i]=str[i]+32; i.e. str[2]=str[2]+32; i.e. str[2]= 68+32; hence str[1]=100 hence str[2]=’d’
4th iteration for(i=3;i<str.length;i++) i.e. for(i=3;3<4;i++)
if(str[i]>=’A’ && str[i]<=’Z’) i.e. if(str[1]>=’A’ && str[1]<=’Z’) hence(‘E’>=’A’ && ‘E'<=’Z’) true
str[i]=str[i]+32; i.e. str[3]=str[3]+32; i.e. str[3]=69+32; hence str[0]=101 hence str[3]=’e’
For Loop ends here as i=4 which is not less than 4.