Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Mixed Case Converter
- if (choice == 3 && choiceGiven)
- {
- for (int i = 0; i < sentence.length(); i++)
- {
- letter[i] = sentence.charAt(i); //breaks down sentence into array of characters
- charInt[i] = (int)letter[i]; //converts array of characters into ascii integers
- //Converts everything to lowercase to make it easier to convert first letters
- if (charInt[i] > 64 && charInt[i] < 91)
- {
- charInt[i] += 32;
- letter[i] = (char)charInt[i];
- }
- //Converts ONLY first letter to uppercase by changing the ascii number
- /**I only changed the first letter to uppercase because the next if statement requires
- * the lowercase letter to be after a space character but since the first character of
- * the sentence CANNOT have spacing, it crashes the programing given an error regarding
- * -1 index position. This is the fix.
- */
- if (charInt[0] > 96 && charInt[0] < 123)
- {
- charInt[i] -= 32;
- letter[i] = (char)charInt[i];
- }
- //Converts ALL first letters to uppercase by changing the ascii number
- if (charInt[i] > 96 && charInt[i] < 123 && letter[i-1] == (char)32)
- {
- charInt[i] -= 32;
- letter[i] = (char)charInt[i];
- }
- //Excludes number using carriage return character(13) which deletes the text and goes to previous character
- if (charInt[i] > 47 && charInt[i] < 58 && omitLettersGiven == true)
- {
- charInt[i]= 13;
- letter[i] = (char)charInt[i];
- }
- builtWord += letter[i]; //Rebuilts sentence using NEW chracters
- }
- System.out.println ("\n");
- System.out.println(builtWord); //Outputs word
- System.out.println ("\n");
- builtWord = ""; //Resets value of the builtWord so if user chooses to try another case the new word doesn't build on the old word
- choiceGiven = false; //Allows user to try another case converter since the current one just finished
- }
Add Comment
Please, Sign In to add comment