Computer Applications
Define a class to accept a string, and print the characters with the uppercase and lowercase reversed, but all the other characters should remain the same as before.
EXAMPLE:
INPUT : WelCoMe2022 OUTPUT : wELcOmE2022
Answer
import java.util.Scanner;
public class KboatChangeCase
{
public static void main(String args[])
{
Scanner in = new Scanner(System.in);
System.out.println("Enter a string:");
String str = in.nextLine();
int len = str.length();
String rev = "";
for (int i = 0; i < len; i++)
{
char ch = str.charAt(i);
if (Character.isLetter(ch))
{
if(Character.isUpperCase(ch))
{
rev += Character.toLowerCase(ch);
}
else
{
rev += Character.toUpperCase(ch);
}
}
else
{
rev += ch;
}
}
System.out.println(rev);
}
}
Variable Description Table
Program Explanation
Output
Related Questions
Define a class to declare a character array of size ten. Accept the characters into the array and display the characters with highest and lowest ASCII (American Standard Code for Information Interchange) value.
EXAMPLE :
INPUT:
'R', 'z', 'q', 'A', 'N', 'p', 'm', 'U', 'Q', 'F'
OUTPUT :
Character with highest ASCII value = z
Character with lowest ASCII value = ADefine a class to declare an array of size twenty of double datatype, accept the elements into the array and perform the following :
Calculate and print the product of all the elements.
Print the square of each element of the array.
Define a class to declare an array to accept and store ten words. Display only those words which begin with the letter 'A' or 'a' and also end with the letter 'A' or 'a'.
EXAMPLE :
Input : Hari, Anita, Akash, Amrita, Alina, Devi Rishab, John, Farha, AMITHA
Output: Anita
Amrita
Alina
AMITHADefine a class to accept two strings of same length and form a new word in such a way that, the first character of the first word is followed by the first character of the second word and so on.
Example :
Input string 1 – BALL
Input string 2 – WORDOUTPUT : BWAOLRLD