Code is copied!
Question 5
Define a class to accept a string and convert the same to uppercase, create and display the new string by replacing each vowel by immediate next character and every consonant by the previous character. The other characters remain the same.
Example:
Input : #IMAGINATION@2024
Output : #JLBFIMBSIPM@2024
Solution:
,
import java.util.Scanner;
class StringManipulation
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
System.out.print("Enter a string: ");
String input = sc.nextLine();
String str = input.toUpperCase();
String result = "";
for (int i = 0; i < str.length(); i++)
{
char ch = str.charAt(i);
if (ch == 'A' || ch == 'E' || ch == 'I' || ch == 'O' || ch == 'U')
{
result += (char)(ch + 1);
}
else if (ch >= 'B' && ch <= 'Z')
{
result += (char)(ch - 1);
}
else
{
result += ch;
}
}
System.out.println("Output: " + result);
}
}
Define a class to accept a string and convert the same to uppercase, create and display the new string by replacing each vowel by immediate next character and every consonant by the previous character. The other characters remain the same. Example: Input : #IMAGINATION@2024 Output : #JLBFIMBSIPM@2024
Solution:
,
import java.util.Scanner;
class StringManipulation
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
System.out.print("Enter a string: ");
String input = sc.nextLine();
String str = input.toUpperCase();
String result = "";
for (int i = 0; i < str.length(); i++)
{
char ch = str.charAt(i);
if (ch == 'A' || ch == 'E' || ch == 'I' || ch == 'O' || ch == 'U')
{
result += (char)(ch + 1);
}
else if (ch >= 'B' && ch <= 'Z')
{
result += (char)(ch - 1);
}
else
{
result += ch;
}
}
System.out.println("Output: " + result);
}
}