Problem: it print "null" in front of every line
for example
input
this is sparta
output
nullhistay isay partasay
import java.util.*;
public class PigLatin
{
String[] piggieLatin;
String[] sentence;
public PigLatin(String[] random)
{
sentence = random;
piggieLatin = new String[sentence.length];
}
//repalce everything beside a~z with space
public String punctuationFree(String abc)
{
return abc.replaceAll("[^a-z]", " ");
}
//read a string, check if the first letter is vowl, and then translate the text.
public String piggie (String t)
{
if (t.charAt(0) == 'a' || t.charAt(0) == 'e' || t.charAt(0) == 'i' || t.charAt(0) == 'o' || t.charAt(0) == 'u')
return t + "ay";
else
return t.substring(1) + t.charAt(0) + "ay";
}
String result;
StringTokenizer pL;
String[] temp;
//lowercase all line, remove punctuation, use tokenizer separate word by word, translate the text, put them back together
public void pigAll()
{
for (int k = 0; k < sentence.length; k++)
{
if(sentence[k] == null){continue;}
sentence[k] = sentence[k].toLowerCase();
sentence[k] = punctuationFree(sentence[k]);
pL = new StringTokenizer(sentence[k]);
while (pL.hasMoreTokens())
{
String temp = pL.nextToken();
temp = piggie(temp);
piggieLatin[k] += temp + " ";
}
}
}
//print the translation.
public void pigReport()
{
for (int j = 0; j<piggieLatin.length; j++)
{
if(piggieLatin[j] == null){continue;}
System.out.println(piggieLatin[j]);
}
}
}