shivamisone

samplepaper2ques8

Aug 22nd, 2023
821
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.57 KB | Source Code | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class stringfun {
  4.     static String str = "";
  5.  
  6.     public static void main(String[] args) {
  7.         stringfun ob = new stringfun();
  8.         ob.input();
  9.         ob.words();
  10.         ob.frequency();
  11.     }
  12.  
  13.     void input() {
  14.         Scanner sc = new Scanner(System.in);
  15.         str = sc.nextLine();
  16.     }
  17.  
  18.     void words() {
  19.         String k = str;
  20.         int up = 0, vow = 0, wor = 1;
  21.         for (int i = 0; i < k.length(); i++) {
  22.             char c = k.charAt(i);
  23.             String s = ("" + c).toUpperCase();
  24.             String l = "" + c;
  25.             if (s.equals(l)) {
  26.                 up++;
  27.             }
  28.             if (c == ' ')
  29.                 wor++;
  30.             if (s.equals("A") || s.equals("E") || s.equals("I") || s.equals("O") || s.equals("U"))
  31.                 vow++;
  32.         }
  33.         System.out.println("number of words:" + wor);
  34.         System.out.println("number of vowels:" + vow);
  35.         System.out.println("number of uppercase letters:" + up);
  36.         System.out.println("");
  37.     }
  38.  
  39.     void frequency() {
  40.         String k = str;
  41.         for (int i = 0; i < k.length(); i++) {
  42.             char c = k.charAt(i);
  43.             int count = 0;
  44.             for (int j = 0; j < k.length(); j++) {
  45.                 if (k.charAt(j) == c) {
  46.                     count++;
  47.                     k = k.substring(0, j) + "*" + k.substring(j + 1);
  48.                 }
  49.             }
  50.             if (c != '*') {
  51.                 System.out.println("frequency of: " + c + " is: " + count);
  52.             }
  53.         }
  54.     }
  55.  
  56. }
  57.  
Advertisement
Add Comment
Please, Sign In to add comment