Computer Science, asked by lepcharenzongcalvin, 9 months ago

Write a program in java to input a string and print its vowels in ascending order

Answers

Answered by vedantddalal
1

Answer:

import java.io.BufferedReader;

import java.io.InputStreamReader;

class Main {

public static void main(String[] args) throws Exception {

BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

String str = br.readLine();

//Array to store the number of vowels

int[] arr = new int[5];

for ( int i = 0; i < str.length(); i++ ) {

if( str.charAt(i) == 'a')

arr[0]++;

else if ( str.charAt(i) == 'e')

arr[1]++;

else if ( str.charAt(i) == 'i')

arr[2]++;

else if ( str.charAt(i) == 'o')

arr[3]++;

else if ( str.charAt(i) == 'u')

arr[4]++;

}

///StringBuffer to append the strings

StringBuffer sb = new StringBuffer("");

for (int i = 0; i < 5; i++ ) {

for ( int j = 0; j < arr[i]; j++ ){

if (i == 0)

sb.append("a");

else if (i == 1)

sb.append("e");

else if (i == 2 )

sb.append("i");

else if (i == 3)

sb.append("o");

else

sb.append("u");

}

}

System.out.println(sb.toString());

}

}

Similar questions