The Artima Developer Community
Sponsored Link

Java Buzz Forum
Java program to reverse vowels of a string

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
instanceof java

Posts: 576
Nickname: instanceof
Registered: Jan, 2015

instanceof java is a java related one.
Java program to reverse vowels of a string Posted: Jul 17, 2016 3:03 AM
Reply to this message Reply

This post originated from an RSS feed registered with Java Buzz by instanceof java.
Original Post: Java program to reverse vowels of a string
Feed Title: Instance Of Java
Feed URL: http://feeds.feedburner.com/blogspot/TXghwE
Feed Description: Instance of Java. A place where you can learn java in simple way each and every topic covered with many points and sample programs.
Latest Java Buzz Posts
Latest Java Buzz Posts by instanceof java
Latest Posts From Instance Of Java

Advertisement

Program : Java example program to Reverse Vowels  in a String



  1. package inheritanceInterviewPrograms;
  2. /*
  3.  * @www.instanceofjava.com
  4.  */
  5. public class ReverseVowels {
  6.     public static String reverseVowels(String string) {
  7.  
  8.         String vowelsStr = "aeiouAEIOU";
  9.  
  10.         int lo = 0;
  11.         int hi = string.length() - 1;
  12.         char[] ch = string.toCharArray();
  13.  
  14.  while (lo < hi) {
  15.  
  16.      if (!vowelsStr.contains(String.valueOf(string.charAt(lo)))) {
  17.                 lo++;
  18.                 continue;
  19.        }
  20.  
  21.     if (!vowelsStr.contains(String.valueOf(string.charAt(hi)))) {
  22.                 hi--;
  23.                 continue;
  24.        }
  25.  
  26.     // swaping variables
  27.      swap(ch, lo, hi);
  28.             lo++;
  29.             hi--;
  30.       }
  31.  
  32.         return String.valueOf(ch);
  33.     }
  34.  
  35. private static void swap(char[] ch, int lo, int hi) {
  36.  
  37.         char temparray = ch[lo];
  38.         ch[lo] = ch[hi];
  39.         ch[hi] = temparray;
  40.  
  41.  }
  42.     
  43. public static void main (String args[]) {
  44.         
  45.          
  46.  System.out.println("After reversing vowels in a string="reverseVowels("InstanceOfjava"));
  47.         
  48.          
  49. }
  50.  
  51. }
Output:


  1. After reversing vowels in a string=anstancOefjavI


Read: Java program to reverse vowels of a string

Topic: Kids : Shapes_V6 Previous Topic   Next Topic Topic: 63% off Gadget Guard iPhone 6 Plus Screen Protector - Deal Alert

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use