-1

I'm working on a project for my Programming Applications course with WGU. I've decided to adapt a python-based pig latin converter from the previous course. I've almost got it done, but when I run the program, I get an extra word. For example, if I enter Latin, it prints atinLay, then on the next line, prints inLatay.

enter image description here

I'm not sure which part of the code is causing this. I know it should be a simple fix but I just can't find it. Here is my code:

import java.util.Scanner; 

public class PigConverter
{ 
public static void main(String[] args) 
    { 
Scanner anscay = new Scanner(System.in);
System.out.print("Enter a word:"); 
String word = anscay.nextLine(); 
System.out.println("This word, in pig latin, would be:");

String pigConvert;
 for (int i=0; i < word.length(); i++)
        {
       if(word.charAt(i)=='a' || word.charAt(i)=='e' || word.charAt(i)=='i' ||
           word.charAt(i)=='o' || word.charAt(i)=='u') 
            {
              String second = word.substring(0,i);
              String first = word.substring(i,word.length());
              System.out.println(first+second+"ay");    
            }

        }
    }
}
Jim Garrison
  • 85,615
  • 20
  • 155
  • 190
  • so what should be the expected outcome for latin? – Maciej Kowalski Jan 28 '17 at 22:18
  • @MaciejKowalski *Pig Latin. It's basically just English, where the first letter is moved to the end, and "ay" is added if it was a consonant. – Carcigenicate Jan 28 '17 at 22:21
  • You should put program results inline, because every link is eventually a dead link. What have you tried? What were the results? Since you are getting extra results, you will have to concentrate on the conditions of the for loop. –  Jan 30 '17 at 01:28

1 Answers1

2

I think that your loop is finding BOTH vowels in the word, so it/s doing the output twice. I think that your loop should break once you find the first vowel.

Thomas Hedden
  • 403
  • 3
  • 9