Skip to main content

SWAP EACH CONSECUTIVE PAIRS UNTIL THERE IS NO PAIR and THEN REVERSE THE VOWELS ---> INPUT:-NAGIEM OUTPUT:-ENIGMA

/* package whatever; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;a

/* Name of the class has to be "Main" only if the class is public. */
class Ideone
{
public static void main (String[] args) throws java.lang.Exception
{
Scanner input = new Scanner(System.in);
String s = input.nextLine();
char[] sCharArray = s.toCharArray();
char[] newWordArray = new char[sCharArray.length];
char temp;
int firstletter=0;
int secondletter=1;
int length = sCharArray.length;
for(int i=0,n=length/2;i<n;i++)
{
temp= sCharArray[firstletter];
sCharArray[firstletter]=sCharArray[secondletter];
sCharArray[secondletter]=temp;
firstletter=firstletter+2;
secondletter=secondletter+2;
}
String news = new String(sCharArray);
System.out.println(news);
int j=0;
for(int i=0,n=sCharArray.length;i<n;i++)
{
if(Character.toLowerCase(sCharArray[i])=='a'||Character.toLowerCase(sCharArray[i])=='e'||Character.toLowerCase(sCharArray[i])=='i'||Character.toLowerCase(sCharArray[i])=='o'||Character.toLowerCase(sCharArray[i])=='u')
{
newWordArray[j]=sCharArray[i];
j++;
}
}
int end = j-1;
for(int i=0,n=sCharArray.length;i<n;i++)
{
if(Character.toLowerCase(sCharArray[i])=='a'|| Character.toLowerCase(sCharArray[i])=='e'||Character.toLowerCase(sCharArray[i])=='i'||Character.toLowerCase(sCharArray[i])=='o'||Character.toLowerCase(sCharArray[i])=='u')
{
sCharArray[i]=newWordArray[end];
end--;
}
}
String finalAnswer = new String(sCharArray);
System.out.println(finalAnswer);

}

}

Comments

Popular posts from this blog

BEGINNER's ALPHABET PALINDROME

PRINT ALPHABET PALINDROMIC PYRAMID USING C# using System; public class Test {       public static void Main()       {             var number = Console.ReadLine();             int n = Convert.ToInt32(number);             Pattern print = new Pattern();             print.PrintPalindromePattern(n);       } } public class Pattern {       public void PrintPalindromePattern(int n)       {             int dummy = 1;             char letter = 'A';             int reversep...

Print word pattern - odd letters - beginner's code

1. Print the word with odd letters as P M R A O R G O R R A P M Solution: using System; public class Test { public static void Main() { string text = Console.ReadLine(); int n=text.Length; Pattern print = new Pattern (); print.XPattern(text,n); } } public class Pattern { public void XPattern(string text,int n) { char[] textarray = text.ToCharArray(); int reverseprinter = n-1; int middleLetter = n/2; for(int i=0;i<n;i++) { for(int j=0;j<n;j++) { if(i==j && j!=middleLetter) { Console.Write(textarray[j]); } else if(j==reverseprinter) { Console.Write(textarray[reverseprinter]); reverseprinter--; } else { Console.Write("*"); } } Console.WriteLine(); } } } OUTPUT Please Enter text: INPUT : program p m r a o r g o r r a p m

MINIMUM DISTANCE BETWEEN TWO SIMILAR STRINGS

LATEST using System ; using System . Linq ; public class Test { public static void Main () { int arrayLength ; int T = Convert . ToInt32 ( Console . ReadLine ()); for ( int i = 0 ; i < T ; i ++) { arrayLength = Convert . ToInt32 ( Console . ReadLine ()); string Line = Console . ReadLine (); GetMinimumDistanceBetweenStrings ( arrayLength , Line ); } } public static void GetMinimumDistanceBetweenStrings ( int length , string Line ) { int min = - 1 ; int initial = 0 ; string [] stringArray = Line . Split ( " " ); for ( int start = 0 ; start < length - 1 ; start ++) { for ( int a = start + 1 ; a <= length - 1 ; a ++) { if ( stringArray [ start ]== stringArray [ a ]) { if ( initial == 0 ) ...