pig latin translator error help

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • mastern200
    New Member
    • Oct 2006
    • 16

    pig latin translator error help

    Hello there. i need some help finishing up my pig latin translator program. It compiles fine, but when i run it and try to translate a sentence, it gives me a syntax error and i cannot see the error. i am almost done with it, please help!

    Code:
    import java.io.*;
    import java.util.*;
    import java.lang.String;
    
    public class IgLatinPay
    {
    	public static void main(String [] args)
    	{
    		String temporary = " ";
    		String piglatin = " ";
    
    		Scanner input = new Scanner(System.in);
    		System.out.println("Enter sentence that you want to translate: ");
    		String english = input.nextLine();
    
    		while(english.indexOf(' ') != -1)
    		{
    			temporary=english.substring(0,english.indexOf(' '));
    			english=english.substring(english.indexOf(' '));
    
    			if(temporary.charAt(0)=='a' || temporary.charAt(0)=='e' || temporary.charAt(0)=='i' || temporary.charAt(0)=='o' || temporary.charAt(0)=='u')
    			{
    				piglatin=temporary+"way";
    				System.out.println(piglatin);
    			}
    			else
    			{
    				char firstChar = temporary.charAt(0);
    				piglatin=temporary.substring(1,temporary.indexOf(' '))+ firstChar +"ay";
    				System.out.println(piglatin);
    			}
    			piglatin+=temporary+" ";
    		}
    	}
    }
  • Laharl
    Recognized Expert Contributor
    • Sep 2007
    • 849

    #2
    Line 29 looks like it has multiple (I can't quite tell how many, it's either 2 or 3) spaces in between the ' ', which would cause an error since it isn't a single character.

    Comment

    • r035198x
      MVP
      • Sep 2006
      • 13225

      #3
      What is the error given by the compiler? It helps to specify these things when posting your questions.

      Comment

      Working...