Created
April 14, 2022 14:20
-
-
Save aadipoddar/bf1d5b24c21a65b1dd67895f8a25d885 to your computer and use it in GitHub Desktop.
Rearrange the Word according to position of Vowel
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Input a word check for the position of the first occurring vowel and perform the following operation. | |
(a) Words that begin with a vowel are concatenated with “Y”. | |
Eg: EUROPE becomes EUROPEY | |
(b) Words that contain a vowel in-between should have the first part from the position of the vowel till the end, | |
followed by the part of the string from beginning till the position of the vowel and is concatenated by "C". | |
Eg: PROJECT becomes OJECTPRC | |
(c) Words which do not contain a vowel are concatenated with "N”. | |
Eg: SKY becomes SKYN | |
*/ | |
import java.util.Scanner; | |
class RearrangeVowel { | |
public static void main(String[] args) { | |
Scanner sc = new Scanner(System.in); | |
System.out.println("Enter a word: "); | |
String word = sc.nextLine(); | |
word = word.toUpperCase(); | |
int vowelPosition = 0; | |
boolean isVowelPresent = false; | |
for (int i = 0; i < word.length(); i++) | |
if (word.charAt(i) == 'A' || word.charAt(i) == 'E' || word.charAt(i) == 'I' || word.charAt(i) == 'O' | |
|| word.charAt(i) == 'U') { | |
vowelPosition = i; | |
isVowelPresent = true; | |
break; | |
} | |
if (!isVowelPresent) | |
System.out.println(word + "N"); | |
else if (vowelPosition == 0) | |
System.out.println(word + "Y"); | |
else | |
System.out.println(word.substring(vowelPosition, word.length()) + "C" + word.substring(0, vowelPosition)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment