_____________ __ _ _ _ _ _ _ .................
..................................
Write a program to enter a sentence and convert each vowel into its next character and print both its Original & Modified sentence...
For eg:
Input => COMPUTER IS FUN
Output => CPMPVTFR JS FVN
______________ _ _ _ _ _ _ _ _ _
Answers
Sample Program to Replace vowels with other alphabets:
import java . util.*;
class Brainly
{
public static void main(String args[])
{
char c;
String vow, s = " " ;
Scanner demo = new Scanner(System.in);
System. out. print("Input => ");
vow = demo . nextLine();
for(int i = 0; i < vow.length(); i++)
{
c =vow. charAt(i);
int n = c;
if(c == 'a' || c == 'A' || c == 'e' || c == 'E' || c == 'i' || c == 'I' || c == 'o' || c == 'O' || c == 'u' || c == 'U')
{
c = (char)(n + 1);
s = s + c;
}
else
{
s = s + c;
}
}
System. out. print("Output =>" +s);
}
}
Output:
Input => COMPUTER IS FUN
Output => CPMPVTFR JS FVN
Hope it helps!
mark me as brainliest answer
hope it help you
/ C++ program to reverse order of vowels
#include<bits/stdc++.h>
using namespace std;
// utility function to check for vowel
bool isVowel(char c)
{
return (c=='a' || c=='A' || c=='e' ||
c=='E' || c=='i' || c=='I' ||
c=='o' || c=='O' || c=='u' ||
c=='U');
}
// Function to reverse order of vowels
string reverseVowel(string str)
{
int j=0;
// Storing the vowels separately
string vowel;
for (int i=0; str[i]!='\0'; i++)
if (isVowel(str[i]))
vowel[j++] = str[i];
// Placing the vowels in the reverse
// order in the string
for (int i=0; str[i]!='\0'; i++)
if (isVowel(str[i]))
str[i] = vowel[--j] ;
return str;
}
// Driver function
int main()
{
string str = "hello world";
cout << reverseVowel(str);
return 0;
}
Output:
hollo werld
Time complexity : O(n) where n = length of string
Auxiliary Space : O(v) where v = number of vowels in string
A better solution is to use two pointers scanning from beginning and end of the array respectively and manipulate vowels pointed by these pointers.
// C++ program to reverse order of vowels
#include<bits/stdc++.h>
using namespace std;
// utility function to check for vowel
bool isVowel(char c)
{
return (c=='a' || c=='A' || c=='e' ||
c=='E' || c=='i' || c=='I' ||
c=='o' || c=='O' || c=='u' ||
c=='U');
}
// Function to reverse order of vowels
string reverseVowel(string str)
{
// Start two indexes from two corners
// and move toward each other
int i = 0;
int j = str.length()-1;
while (i < j)
{
if (!isVowel(str[i]))
{
i++;
continue;
}
if (!isVowel(str[j]))
{
j--;
continue;
}
// swapping
swap(str[i], str[j]);
i++;
j--;
}
return str;
}
// Driver function
int main()
{
string str = "hello world";
cout << reverseVowel(str);
return 0;