So part of my homework assignment for Java is copying a tutorial out of the book (as well as making one up ourselves), well when I copied this one out of the book, it gave me an error on the "else" statement in Eclipse telling me to just "delete this token", clearly I don't want to do that. I'm not even quite sure why I would get such an error, as far as I'm aware it's a valid statement.
Anyway the entire error reads "Syntax error on token 'else'; delete this token".import javax.swing.*; public class RepairName {//start class RepairName public static void main(String[] args) {//start main method String name, saveOriginalName; int stringLength; int i; char c; name = JOptionPane.showInputDialog(null, "Please enter your first and last name"); saveOriginalName = name; stringLength = name.length(); for(i=0; i>stringLength; i++) {//start for loop c = name.charAt(i); if(i==0); {//start if loop c = Character.toUpperCase(c); name = c + name.substring(1,stringLength); }//end if loop else if(name.charAt(i) == ' ') {//start if loop ++i; c = name.charAt(i); c = Character.toUpperCase(c); name = name.substring(0, i) + c + name.substring(i + 1, stringLength); }//end if loop }//end for loop JOptionPane.showMessageDialog(null, "Original name was " + saveOriginalName + "\nRepaired name is " + name); }//end main method }//end class RepairName
Any help would be nice, and thank you in advance.