In: Computer Science
Write a program that will take a line of input and go through and print out that line again with all the uppercase letters swapped with the lowercase letters. JAVA
Using printf
Code:
import java.util.*;
class a
{
public static void main(String args[])
//main
method
{
Scanner sc=new
Scanner(System.in);
//creating
an object for scanner
String str=sc.nextLine();
int i,j;
char
s[]=str.toCharArray();
//converting to array of
characters since we can't change a string
int len=s.length;
//finding the length of the string
i=0;
while(i!=len)
{
if(s[i]>='a'
&& s[i]<='z')
s[i]=(char)(s[i]-32);
//converting lower to upper
case
else
if(s[i]>='A' && s[i]<='Z')
//converting upper to lower
case
s[i]=(char)(s[i]+32);
i++;
}
for(i=0;i<len;i++)
{
System.out.printf("%c",s[i]);
//printing the string character wise
}
System.out.println("\n");
}
}