Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I want this program to print the number of e or E in a sentence.But when l run i

ID: 3614403 • Letter: I

Question

I want this program to print the number of e or E in a sentence.But when l run it is counts them like 1,2,3 instead of just sayingthey are three e|E's in the sentence. How can l solve thisproblem.

import javax.swing.*;

public class Exam2
{
    public static void main (String [] rhema)

    {
        double countVowelsAa=0;
        double countVowelsEe=0;
        double countVowelsIi=0;
        double countVowelsOo=0;
        double countVowelsUu=0;

        double countSentences=0;
        double countWords=0;
        double countCharacters=0;

        boolean done=false;

        while(!done){

            String sentence = JOptionPane.showInputDialog("Enter a anysentence");

            if(sentence.equalsIgnoreCase("q")==true)

                       done=true;
                    else{

                        for (int i = 0; i < sentence.length(); i++)
                                {
                                  char c = sentence.charAt(i);



                                          if (c=='e'||c=='E')countVowelsEe++;

                                              {
                                                System.out.println(countVowelsEe);
                                             }
                                         }
                                     }
                                  }
                              }
                          }




Explanation / Answer

You need to put your println inside the outerloop but outside the inner loop to print once for eachsentence. import javax.swing.*; public class Exam2 { publicstatic void main (String []rhema) { double countVowelsAa=0; double countVowelsEe=0; double countVowelsIi=0; double countVowelsOo=0; double countVowelsUu=0; double countSentences=0; double countWords=0; double countCharacters=0; boolean done=false; while(!done) { String sentence = JOptionPane.showInputDialog("Enter a any sentence"); if(sentence.equalsIgnoreCase("q")==true) {    done=true; } else {    for (int i = 0; i
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote