0

/*
For this program you will be working with strings. You are to ask
the user to input a string. Then, make (and print out) the "pig
latin like" version of this string by using the following rule:


1) words beginning with a vowel (A, E, I, O, U) , have the word "yo"
appended to the word
2) words beginning with a consonant, move the first character to the
end of the word and append "oy"


For example, if the user inputs:

mary had a little lamb

You should output:

arymoy adhoy ayo ittleloy ambloy

This program is due Wednesday, the 15th of October.

HINT: The indexOf() and substring() methods can be used to extract
each word in the string. Now with a particular word, we can
use charAt to get the first character and check if it's a
vowel. If needed, we can use substring() again to get the
string consisting of the 2nd to the last character and "tack
on" the first character plus "oy".

4
Contributors
3
Replies
5
Views
14 Years
Discussion Span
Last Post by JamesCherrill
0

I read in your post that your assignment was due a few days ago, but I thought I might give you a link to a program that reminds me very much of your assignment:

PigLatin.java
PigLatinTranslator.java

You can find these java classes and such to study if you go to the following site:

http://duke.csc.villanova.edu/jss1/bookResources/examples.jsp

They are stored in the "Chapter 4" example bundle.

/Soo-Im

0
//AUTHOR ANIL KUMAR REDDY
package demoexetest;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class DemoEx1 {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String str = br.readLine();
        String[] temp;
        String last = null;
        String delimiter = " ";

        temp = str.split(delimiter);
        for (int i = 0; i < temp.length; i++) {
            char first = '\u0000';
            String s = "";

            char[] third = temp[i].toCharArray();
            for (int counter = 0; counter < third.length; counter++) {
                //IF VOWELS
                if (third[0] == 'a' || third[0] == 'e' || third[0] == 'i'
                        || third[0] == 'o' || third[0] == 'u') {
                    last = "yo";
                } else {
                    //ESLE CONSONENTS
                    last = "oy";
                }
                if (counter == 0) {
                    first = third[0];
                } else
                    s = s + third[counter];
            }
            System.out.print(s + first + last);
            System.out.print(" ");
        }

    }
}
0

Hello Anil
Your solution comes 8 years too late for the OP, and anyway we don't do peole's homework for them, we try to teach them to do it for themselves.

Edited by JamesCherrill

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.