Work in HR or Recruiting?
Apollo Group
www.apollogrp.edu Phoenix, AZ 5000+ Employees
Work in HR? Complete Your Profile

26 interview experiences Back to all Apollo Group Interview Questions & Reviews

Interview Question for Software Engineer II at Apollo Group:
Jan 10, 2012

Write a program that reverses only consonants in a string.


Add Tags [?]

See more for this Apollo Group Software Engineer II Interview

Helpful Question?  
Yes | No
Inappropriate?

Answers & Comments (1)

Jun 29, 2012

by khan:

/**
 *
 */
package codesamples;

import java.util.Scanner;

/**
 * @author Owner
 *
 */
public class InverseConsonants
{

    /**
     *
     */
    public InverseConsonants()
    {
        // TODO Auto-generated constructor stub
    }

    /**
     * @param args
     */
    public static void main(String[] args)
    {
        // TODO Auto-generated method stub
        System.out.print("Please enter a string to reverse the consonants in a string: ");
        Scanner input = new Scanner(System.in);

        String line = input.nextLine();

        char[] cArray = line.toCharArray();

        StringBuffer sb = new StringBuffer();
        //System.out.println("---------: " + sb.append(cArray));
        //System.exit(0);
        for (int c = 0; c < cArray.length; ++c) //> c : line.toCharArray())
        {

            //System.out.println(c);
            char cc = cArray[c];
            //System.exit(0);
            switch (cc)
            {
                case 'a':
                    System.out.println("The vowel is " + cArray[c]);
                    cArray[c] = ' ';
                    break;

                case 'e':
                    //System.out.println("The vowel is " + sb.charAt(c));
                    //sb.deleteCharAt(c);
                    System.out.println("The vowel is " + cArray[c]);
                    cArray[c] = ' ';
                    break;

                case 'i':
                    System.out.println("The vowel is " + cArray[c]);
                    cArray[c] = ' ';
                    break;
                case 'o':
                    System.out.println("The vowel is " + cArray[c]);
                    cArray[c] = ' ';
                    break;
                case 'u':
                    System.out.println("The vowel is " + cArray[c]);
                    cArray[c] = ' ';
                    break;

                default:
                    //
                    break;

            }

        }//while
        sb.append(cArray);
        String s = sb.toString();
        System.out.println(s);
        sb.reverse();
        s = sb.toString();
        System.out.println("Inverse is " + s);

    }

}
Helpful Answer?  
Yes | No
Inappropriate?

To comment on this question, Sign In with Facebook or Sign Up

Tags are like keywords that help categorize interview questions that have something in common.