public class Binnenmajuskel extends MiniJava { public static void main(String[] args) { String startCase = ""; String upperCase = ""; String snakeCase = ""; String pascalCase = ""; // ask user for next term, check if it's valid, modify it in the // given manner (startcase, uppercase, ...) and append it to variables: while (true) { String input = readString("Begriff eingeben:"); // empty string -> done if (input.length() == 0) break; // exit loop // check if input is valid; and save it all lowercase String lowerInput = ""; boolean valid = true; for (int i = 0; i < input.length(); ++i) { char c = input.charAt(i); if (c >= 'A' && c <= 'Z') // A-Z lowerInput += (char) (c+32); else if (c >= 'a' && c <= 'z') // a-z lowerInput += c; else { // invalid valid = false; break; // exit loop (not required) } } if (!valid) { // not valid = (valid == false) write("Diese Eingabe ist unültig (nur Buchstaben und Unterstriche)!"); continue; // continue loop (wait for next input) } // append modified string to the variables: if (snakeCase.length() > 0) // is not first word snakeCase += '_'; for (int i = 0; i < lowerInput.length(); ++i) { char c = lowerInput.charAt(i); upperCase += (char) (c-32); // UPPERCASE snakeCase += c; // snake_case // PascalCase if (i >= 1) pascalCase += c; else // -> upper char if at first char (and is not underscore) pascalCase += (char) (c-32); // Startcase: if (i > 0 || startCase.length() > 0) startCase += c; else // -> upper char if at first char in first word (and is not underscore) startCase += (char) (c-32); } } write("Startcase: " + startCase + "\n" + "UPPERCASE: " + upperCase + "\n" + "snake_case: " + snakeCase + "\n" + "PascalCase: " + pascalCase + "\n"); } }