Here's my code :
public class PigLatinizer {
public static int pigLatinOut(String originalWord) {
int index;
for(int i=0;i<originalWord.length();i++){
if(originalWord.charAt(i)== 'A'||originalWord.charAt(i)=='E' || originalWord.charAt(i) =='I'||originalWord.charAt(i)=='O' ||originalWord.charAt(i)=='U'){
index = i;
}
else{index=0;}
}
return index;
}
public static void main(String[] args){
System.out.println(pigLatinOut("TEST"));
}
}
I dont know what exactly do here, but here's the output :
C:\Users\amarn\IdeaProjects\General Programs\src\PigLatinizer.java:13:16
java: variable index might not have been initialize
""- what would happen?indexbe, if you provided an empty String fororiginalWord?index, as the error message very clearly tells you. The compiler is not wrong. If you never enter the loop, thenindexis never initialized, and that's the problem here