Java-向我的程序中添加基本统计信息

Java-向我的程序中添加基本统计信息,java,java.util.scanner,Java,Java.util.scanner,我创建了一个小的扫描程序,可以删除输入短语的元音。它的工作非常好,除了现在我需要添加一行显示一些简单的统计数据,但我不知道从哪里开始 我目前拥有的: public static void main(String[] args) { new Disemvoweler(); } public Disemvoweler() { System.out.println("Welcome to the disemvoweling utility!\n"); Scanner in =

我创建了一个小的扫描程序,可以删除输入短语的元音。它的工作非常好,除了现在我需要添加一行显示一些简单的统计数据,但我不知道从哪里开始

我目前拥有的:

public static void main(String[] args) {
    new Disemvoweler();
}

public Disemvoweler() {
    System.out.println("Welcome to the disemvoweling utility!\n");
    Scanner in = new Scanner(System.in);
    System.out.println("Enter your phrase: ");
    String input = in.nextLine(); // Take in the input.
    in.close(); // Close the scanner.

    System.out.println("\nYour disemvoweled phrase: "+input.replaceAll("[aeoiu]", ""));
输出:

欢迎使用Disemvowling实用程序

输入您的短语: 谢谢你的帮助

你被剥夺了权力的短语:Thnk y fr yr hlp

我试图添加到输出中的内容:

public static void main(String[] args) {
    new Disemvoweler();
}

public Disemvoweler() {
    System.out.println("Welcome to the disemvoweling utility!\n");
    Scanner in = new Scanner(System.in);
    System.out.println("Enter your phrase: ");
    String input = in.nextLine(); // Take in the input.
    in.close(); // Close the scanner.

    System.out.println("\nYour disemvoweled phrase: "+input.replaceAll("[aeoiu]", ""));

从x减少到x个字符。xx%的降价率

有时应该有人回答这样的问题:)别忘了向你的老师问好:)

1)
计算元音的数量
,然后

2)
计算
原始
字符串和
修改后的
字符串之间的百分比差异

import java.util.Scanner;
class Disemvoweler {
public static void main(String[] args) {
    new Disemvoweler();
}

public Disemvoweler() {
    System.out.println("Welcome to the disemvoweling utility!\n");
    Scanner in = new Scanner(System.in);
    System.out.println("Enter your phrase: ");
    String input = in.nextLine(); // Take in the input.
    int inputLength = input.length();
    in.close(); // Close the scanner.
    int count = 0;
                int vowels = 0;
                int consonants = 0;
                for (int i = 0; i < input.length(); i++)
                {
                        char ch = input.charAt(i);
                        if (ch == 'a' || ch == 'e' || ch == 'i' || 
                                        ch == 'o' || ch == 'u')
                        {
                                vowels++;
                        }
                }
                    System.out.println("\nYour disemvoweled phrase: "+input.replaceAll("[aeoiu]", ""));
                    String disemvoweled = input.replaceAll("[aeoiu]", "");
                    int disemvoweledLength = disemvoweled.length();
                    double percent = Math.abs(100*((double)disemvoweledLength-(double)inputLength)/(double)inputLength);
                    System.out.println("Reduced from: " + inputLength + " to " + disemvoweledLength + " characters. Reduction rate of " + percent + "%");
        }
}
输出:

Your disemvoweled phrase: sd lsdkslkd sdsd ldsdjdqwq sdqw
Reduced from: 49 to 31 characters. Reduction rate of 36.734693877551024%

好的,到目前为止,您试图实现什么?这是一个非常简单的问题:只需比较输入和结果字符串的长度。
Your disemvoweled phrase: sd lsdkslkd sdsd ldsdjdqwq sdqw
Reduced from: 49 to 31 characters. Reduction rate of 36.734693877551024%