Guest User

Untitled

a guest
Jul 21st, 2018
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.62 KB | None | 0 0
  1. //Mixed Case Converter
  2. if (choice == 3 && choiceGiven)
  3. {
  4. for (int i = 0; i < sentence.length(); i++)
  5. {
  6. letter[i] = sentence.charAt(i); //breaks down sentence into array of characters
  7. charInt[i] = (int)letter[i]; //converts array of characters into ascii integers
  8.  
  9. //Converts everything to lowercase to make it easier to convert first letters
  10. if (charInt[i] > 64 && charInt[i] < 91)
  11. {
  12. charInt[i] += 32;
  13. letter[i] = (char)charInt[i];
  14. }
  15.  
  16. //Converts ONLY first letter to uppercase by changing the ascii number
  17. /**I only changed the first letter to uppercase because the next if statement requires
  18. * the lowercase letter to be after a space character but since the first character of
  19. * the sentence CANNOT have spacing, it crashes the programing given an error regarding
  20. * -1 index position. This is the fix.
  21. */
  22. if (charInt[0] > 96 && charInt[0] < 123)
  23. {
  24. charInt[i] -= 32;
  25. letter[i] = (char)charInt[i];
  26. }
  27.  
  28. //Converts ALL first letters to uppercase by changing the ascii number
  29. if (charInt[i] > 96 && charInt[i] < 123 && letter[i-1] == (char)32)
  30. {
  31. charInt[i] -= 32;
  32. letter[i] = (char)charInt[i];
  33. }
  34.  
  35. //Excludes number using carriage return character(13) which deletes the text and goes to previous character
  36. if (charInt[i] > 47 && charInt[i] < 58 && omitLettersGiven == true)
  37. {
  38. charInt[i]= 13;
  39. letter[i] = (char)charInt[i];
  40. }
  41.  
  42. builtWord += letter[i]; //Rebuilts sentence using NEW chracters
  43. }
  44. System.out.println ("\n");
  45. System.out.println(builtWord); //Outputs word
  46. System.out.println ("\n");
  47. builtWord = ""; //Resets value of the builtWord so if user chooses to try another case the new word doesn't build on the old word
  48.  
  49. choiceGiven = false; //Allows user to try another case converter since the current one just finished
  50. }
Add Comment
Please, Sign In to add comment