Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class stringfun {
- static String str = "";
- public static void main(String[] args) {
- stringfun ob = new stringfun();
- ob.input();
- ob.words();
- ob.frequency();
- }
- void input() {
- Scanner sc = new Scanner(System.in);
- str = sc.nextLine();
- }
- void words() {
- String k = str;
- int up = 0, vow = 0, wor = 1;
- for (int i = 0; i < k.length(); i++) {
- char c = k.charAt(i);
- String s = ("" + c).toUpperCase();
- String l = "" + c;
- if (s.equals(l)) {
- up++;
- }
- if (c == ' ')
- wor++;
- if (s.equals("A") || s.equals("E") || s.equals("I") || s.equals("O") || s.equals("U"))
- vow++;
- }
- System.out.println("number of words:" + wor);
- System.out.println("number of vowels:" + vow);
- System.out.println("number of uppercase letters:" + up);
- System.out.println("");
- }
- void frequency() {
- String k = str;
- for (int i = 0; i < k.length(); i++) {
- char c = k.charAt(i);
- int count = 0;
- for (int j = 0; j < k.length(); j++) {
- if (k.charAt(j) == c) {
- count++;
- k = k.substring(0, j) + "*" + k.substring(j + 1);
- }
- }
- if (c != '*') {
- System.out.println("frequency of: " + c + " is: " + count);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment