0

`public class CheckVowelsDigits {

public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    System.out.print("Enter a String: ");
    String string = sc.next();
    int numOfVowels = 0;
    int numOfDigits = 0;
    string = string.toLowerCase();
    for (int i=0;i<string.length();i++){
       char letter = string.charAt(i);
       switch(letter){
           case 'a': 
           case 'e':
           case 'i':
           case 'o':
           case 'u': numOfVowels++; break;
       }
       if (letter >='0' && letter <='9')
          numOfDigits++;
    }
    double perVowels = (numOfVowels*1.0/string.length())*100.0;
    double perDigits = (numOfDigits*1.0/string.length())*100.0;

    System.out.println("Number of vowels: " + numOfVowels + " (" + perVowels + "%)");
    System.out.println("Number of digits: " + numOfDigits + " (" + perDigits + "%)");
}
}`

OUTPUT

Enter a String: test12345

Number of vowels: 1 (11.11111111111111%)

Number of digits: 5 (55.55555555555556%)

BUT I NEED

Number of vowels: 1 (11.11%)

Number of digits: 5 (55.56%)

Mitch
  • 3,342
  • 2
  • 21
  • 31

1 Answers1

-1

double perVowels = Math.round(perVowels * 100.0) / 100.0;

Virat18
  • 3,427
  • 2
  • 23
  • 29