Advertisement
Guest User

Untitled

a guest
Oct 26th, 2016
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.48 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Prog5 {
  4.  
  5. public static void main(String[] args) {
  6. // TODO Auto-generated method stub
  7. Scanner console = new Scanner(System.in);
  8.  
  9. System.out.println("Welcome to the disemvoweling utility!"); // Initially typed "disemboweling" xD
  10. System.out.print("Enter text to be disemvoweled: ");
  11. String inLine = console.nextLine();
  12. String vowels= inLine.replaceAll("[AEIOUaeiou]", ""); // RegEx for vowel control
  13. System.out.println("Your disemvoweled text is: " + vowels); // Prints disemvoweled text
  14.  
  15. // Used to count all characters without counting white space(s)
  16. int reducedAmount = 0;
  17. for (int i = 0, length = inLine.length(); i < length; i++) {
  18. if (inLine.charAt(i) != ' ') {
  19. reducedAmount++;
  20. }
  21. }
  22.  
  23. // newAmount is the number of characters on the disemvoweled text without counting white space(s)
  24. int newAmount = 0;
  25. for (int i = 0, length = vowels.length(); i < length; i++) {
  26. if (vowels.charAt(i) != ' ') {
  27. newAmount++;
  28. }
  29. }
  30.  
  31. int reductionRate = ((newAmount - reducedAmount) / reducedAmount); // Percentage of character reduction
  32.  
  33.  
  34. System.out.print("Reduced from " + reducedAmount + " to " + newAmount + ". Reduction rate is " + reductionRate);
  35.  
  36. }
  37. }
  38.  
  39. Welcome to the disemvoweling utility!
  40.  
  41. Enter text to be disemvoweled: Testing please
  42.  
  43. Your disemvoweled text is: Tstng pls
  44.  
  45. Reduced from 13 to 8. Reduction rate is 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement