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
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
package inheritanceInterviewPrograms; /* * @www.instanceofjava.com */ public class ReverseVowels { public static String reverseVowels(String string) { String vowelsStr = "aeiouAEIOU"; int lo = 0; int hi = string.length() - 1; char[] ch = string.toCharArray(); while (lo < hi) { if (!vowelsStr.contains(String.valueOf(string.charAt(lo)))) { lo++; continue; } if (!vowelsStr.contains(String.valueOf(string.charAt(hi)))) { hi--; continue; } // swaping variables swap(ch, lo, hi); lo++; hi--; } return String.valueOf(ch); } private static void swap(char[] ch, int lo, int hi) { char temparray = ch[lo]; ch[lo] = ch[hi]; ch[hi] = temparray; } public static void main (String args[]) { System.out.println("After reversing vowels in a string="reverseVowels("InstanceOfjava")); } } Output: After reversing vowels in a string=anstancOefjavI
Read: Java program to reverse vowels of a string