Advertisement
RhettD

Java Online

Oct 15th, 2019
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.58 KB | None | 0 0
  1. import java.lang.*;
  2. public class Level14 {
  3.  public static void main(String[] args) {
  4.  
  5.   StringBuilder str = new StringBuilder(args[0]);
  6.   int len = str.length();
  7.   if (len < 4) {
  8.    System.out.println("ERROR! LENGTH OF WORD IS INSUFFICIENT");
  9.    return;
  10.   }
  11.  
  12.   System.out.println("Your word has " + len + " characters.");
  13.  
  14.   char c1 = str.charAt(0);
  15.   char c4 = str.charAt(3);
  16.   System.out.println("The first character in your phrase is " + c1 + ".");
  17.   System.out.println("The fourth character in your phrase is " + c4 + ".");
  18.  
  19.   int index = len - 1;
  20.   System.out.println("The index of the last character is " + index);
  21.  
  22.   char last = str.charAt(len - 1);
  23.   System.out.println("The last character in your phrase is " + last + ".");
  24.  
  25.   int i = 0;
  26.   int n = 0;
  27.  
  28.   while (i < str.length()) {
  29.    char c = str.charAt(i);
  30.    if (c == 't' || c == 'T') {
  31.     n++;
  32.    }
  33.    i++;
  34.   }
  35.   System.out.println("The number of t's or T's (combined) is " + n);
  36.  
  37.   i = 0;
  38.   n = 0;
  39.   while (i < str.length()) {
  40.    char c = str.charAt(i);
  41.    if (str.charAt(i) == 'a' || str.charAt(i) == 'e' || str.charAt(i) == 'i' || str.charAt(i) == 'o' || str.charAt(i) == 'u' || str.charAt(i) == 'A' || str.charAt(i) == 'E' || str.charAt(i) == 'I' || str.charAt(i) == 'O' || str.charAt(i) == 'U') {
  42.     n++;
  43.    }
  44.    i++;
  45.   }
  46.   System.out.println("Your word has " + n + " vowels.");
  47.  
  48.   int d = len - n;
  49.   System.out.println("Your word has " + d + " non-vowels.");
  50.  
  51.   StringBuilder strn = new StringBuilder(args[0]);
  52.   System.out.println("Your word in reverse order is " + strn.reverse());
  53.    
  54.  }
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement