My program receives no errors or run time errors, but for some reason it runs infinitely. I need help pinpointing the problem D:
I will post additional information about the exercise I am trying to solve in this thread.
package captcrunch;
/**
*
* @author Josh
*/
public class Main {
public static String captCrunch (String input, int n) {
// method captCrunch takes a string and produces a new one with
// each character replaced by (character + n).
String message = "";
int index = 0;
int length = input.length();
while (index < length) {
char letter = input.charAt(index);
// letter is the single char pulled from input
int code = letter;
// code will be the new letter produced by adding n
if ('a' <= letter && letter <= 'z') {
// lowercase
code = code + n;
if (code < 'a') {
code = code + 26;
// 26 = num of chars in alphabet, for wrap around
} else if (code > 'z') {
code = code - 26;
}
message = message + (char)code;
} else {
if ('A' <= letter && letter <= 'Z') {
// uppercase
code = code + n;
if (code < 'a') {
code = code + 26;
// 26 = num of chars in alphabet, for wrap around
} else if (code > 'z') {
code = code - 26;
}
message = message + (char)code;
}
}
}
return message;
}
public static void main(String[] args) {
// TODO code application logic here
System.out.println (captCrunch ("hi", 1));
}
}