For a program I'm writing, I'm trying to get rid of doubles in my string (which is a concatenation of a keyword and the alphabet). My code was compiling fine until I added the code about concatenating the substrings before and after the character I'm trying to get rid of.

for (int i = 0; i < fullcrypt.length(); i++) {
							System.out.println("i = " + i);
							System.out.println(fullcrypt.charAt(i));
				for (int j = i+1; j <= fullcrypt.length(); j++) {
							System.out.println("j = " + j);
							System.out.println(fullcrypt.charAt(j));
		//if characters match, recreate string with substrings before and after matching character
					if ((fullcrypt.charAt(i)) == (fullcrypt.charAt(j)) && j != fullcrypt.length)
						fullcrypt = (fullcrypt.substring(0, j) + fullcrypt.substring(j+1));
					else if (fullcrypt.charAt(i) == fullcrypt.charAt(j))
						fullcrypt = (fullcrypt.substring(0,j));
				}
			}

At that point, there are a number of compilation errors demanding a class, interface, or enum for a bunch of things which don't make sense afterwards (ex: for a string, an if statement, etc.), so I'm pretty sure the problem is here, but I'm not sure where.

Thanks!

number of compilation errors

Please copy and paste here the full text of the error messages.

Crypt.java:102: class, interface, or enum expected
                String fullcryptA = fullcrypt.toUpperCase();
                ^
Crypt.java:103: class, interface, or enum expected
                String fullcryptB = fullcrypt.toLowerCase();
                ^
Crypt.java:105: class, interface, or enum expected
                                        System.out.println("fullcrypt caps = " + fullcryptA);
                                        ^
Crypt.java:106: class, interface, or enum expected
                                        System.out.println("fullcrypt lower = " + fullcryptB);
                                        ^
Crypt.java:108: class, interface, or enum expected
                String alphaA = ("ABCDEFGHIJKLMNOPQRSTUVWXYZ");
                ^
Crypt.java:109: class, interface, or enum expected
                String alphaB = ("abcdefghijklmnopqrstuvwxyz");
                ^
Crypt.java:111: class, interface, or enum expected
                                        System.out.println("Alpha = " + alphaA);
                                        ^
Crypt.java:112: class, interface, or enum expected
                                        System.out.println("Alpha = " + alphaB);
                                        ^
Crypt.java:114: class, interface, or enum expected
                char A = alphaA.charAt(i);
                ^
Crypt.java:115: class, interface, or enum expected
                char a = alphaB.charAt(i);
                ^
Crypt.java:117: class, interface, or enum expected
                for (int i=0; i < 26; i++) {
                ^
Crypt.java:117: class, interface, or enum expected
                for (int i=0; i < 26; i++) {
                              ^
Crypt.java:117: class, interface, or enum expected
                for (int i=0; i < 26; i++) {
                                      ^
Crypt.java:120: class, interface, or enum expected
                        else if (c == A)
                        ^
Crypt.java:123: class, interface, or enum expected
                        else if (c == a && i < (25 - key))
                        ^
Crypt.java:125: class, interface, or enum expected
                        else if (c == a)
                        ^
Crypt.java:128: class, interface, or enum expected
                                        System.out.println("next char in txt = " + c);
                                        ^
Crypt.java:130: class, interface, or enum expected
                                        System.out.println("char matched = " + A);
                                        ^
Crypt.java:131: class, interface, or enum expected
                                        System.out.println("char matched = " + a);
                                        ^
Crypt.java:132: class, interface, or enum expected
                }
                ^
Crypt.java:135: class, interface, or enum expected
        }
        ^
Crypt.java:142: class, interface, or enum expected
        public static void encryptFile(FileReader in, FileWriter out, String k, int key) throws IOException {
                      ^
Crypt.java:145: class, interface, or enum expected
                        if (next == -01) return; //end of file
                        ^
Crypt.java:146: class, interface, or enum expected
                        char c = (char)next;
                        ^
Crypt.java:147: class, interface, or enum expected
                        out.write(encrypt(c, k, key));
                        ^
Crypt.java:148: class, interface, or enum expected
                }
                ^
26 errors


They're all error messages from after that point in the code.

Looks like mismatched {}s. The compiler is looking for the start of a class, interface or enum.
Check that all your {}s are correctly paired.

That's what I had assumed, but I can't find any mismatched {}. Further, before the last two lines were added, the program compiled fine, thus my confusion.

Take out the last two lines and see if that corrects the problem.

Some IDEs have {} matching tools. Put your cursor on a {, press a key combo and the cursor moves to the matching }. On mine the combo is CTL + ]

When I deleted the previous code, I had left an extra } in there. Thanks so much!

They can easily hide if you are not careful where you place them.
Some people make them obvious by putting them on a line by themself.

This article has been dead for over six months. Start a new discussion instead.