Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * This Class converts capitals to lower case and
- * small letters to capitals, without changing of
- * special characters.
- * @author Droxl
- */
- public class LetterConverter {
- /**
- * This method changes the character to lower case.
- * @param c The character which is given.
- * @return Returns the lower case character.
- */
- public static char getLowerCase(char c) {
- c = Character.toLowerCase(c);
- return c;
- }
- /**
- * This method changes the character to upper case.
- * @param c The character which is given.
- * @return Returns the upperer case character.
- */
- public static char getUpperCase(char c) {
- c = Character.toUpperCase(c);
- return c;
- }
- /**
- * This method converts capitals to upper or lower case.
- * It depends on which type character is given.
- * @param c The given character.
- * @return Returns the opposite of the
- * type of character which is entered.
- */
- public static char convertLetter(char c) {
- /*This character serves as return-value.*/
- char returnValue;
- /*Here the converting begins...*/
- if ((c == 'a') || (c == 'b') || (c == 'c')
- || (c == 'd') || (c == 'e') || (c == 'f')
- || (c == 'g') || (c == 'h') || (c == 'i')
- || (c == 'j') || (c == 'k') || (c == 'l')
- || (c == 'm') || (c == 'n') || (c == 'o')
- || (c == 'p') || (c == 'q') || (c == 'r')
- || (c == 's') || (c == 't') || (c == 'u')
- || (c == 'v') || (c == 'w') || (c == 'x')
- || (c == 'y') || (c == 'z')) {
- /*...to capitals.*/
- returnValue = getUpperCase(c);
- } else {
- /*In the other case to small letters.*/
- returnValue = getLowerCase(c);
- }
- /*Returns capital or lower case letters depending on what is entered.*/
- return returnValue;
- }
- /**
- * Main-method() which executes the given methods above.
- * @param args is not used.
- */
- public static void main(String[] args) {
- /*Converts to --> A.*/
- System.out.println(convertLetter('a'));
- /*Converts to --> a.*/
- System.out.println(convertLetter('A'));
- /*Keeps steady @.*/
- System.out.println(convertLetter('@'));
- /*Converts to --> B.*/
- System.out.println(convertLetter('b'));
- /*Converts to --> b.*/
- System.out.println(convertLetter('B'));
- /*Keeps steady @.*/
- System.out.println(convertLetter('@'));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement