What's new

Help Hello pa help naman po.

Lhei015

Grasshopper
Joined
Nov 10, 2021
Posts
7
Reaction
1
Points
15
Ito po yung question, ano po ba pag ganito?
  1. Write a recursive method that will return the number of vowels in a given string.
 
Sa next request niyo po try niyo muna mag search sa ddg.gg or google.com
Para mas madali sa mag re reply
Eto po yung isa sa mga result

You do not have permission to view the full content of this post. Log in or register now.

/JAVA CODE/

/RecursiveVowels.java/


Code:
import java.util.Scanner;

/**
 * This class is used to count number of vowels present in given String
 *
 */
public class RecursiveVowels { 

        //Starting point of execution
        public static void main(String args[]) {
                //Scanner is used to take user input from console
                Scanner sc = new Scanner(System.in);
                
                //Asking user to input String to find out vowel count in it
                System.out.println("Enter String to find out number of vowels :");
                //reading user input from console
                String inputString = sc.nextLine();

                // This will print total numbers of Vowel in string 
                System.out.println("Total vowel in the String - "+getVowelCount(inputString,inputString.length())); 
                
                //Closing scanner
                sc.close();
        } 

        /**
         * This method will get count of total number of vowel from 0 to n 
         * @param str
         * @param len
         * @return
         */
        public static int getVowelCount(String str, int len) { 
                if (len == 1) { 
                        return isVowel(str.charAt(len - 1)); 
                }

                //recursive call to countVowel if len is not 1
                return getVowelCount(str, len-1) + isVowel(str.charAt(len - 1)); 
        }

        /**
         * Function to check the character is vowel if yes then return 1 otherwise 0
         * @param ch
         * @return
         */
        public static int isVowel(char ch) { 
                //converting ch to uppercase
                ch = Character.toUpperCase(ch); 
                //checking if ch is A,E,I,O or U
                if(ch=='A' || ch=='E' || ch=='I' || ch=='O' || ch=='U')  {
                        return 1; 
                } else {        
                        return 0;
                }
        } 

}

/Sample Output/

1611201899300_Capture7.jpg
 

Attachments

Thanks much. Napaka buti mo :)

Sa next request niyo po try niyo muna mag search sa ddg.gg or google.com
Para mas madali sa mag re reply
Eto po yung isa sa mga result

You do not have permission to view the full content of this post. Log in or register now.

/JAVA CODE/

/RecursiveVowels.java/


Code:
import java.util.Scanner;

/**
 * This class is used to count number of vowels present in given String
 *
 */
public class RecursiveVowels {

        //Starting point of execution
        public static void main(String args[]) {
                //Scanner is used to take user input from console
                Scanner sc = new Scanner(System.in);
               
                //Asking user to input String to find out vowel count in it
                System.out.println("Enter String to find out number of vowels :");
                //reading user input from console
                String inputString = sc.nextLine();

                // This will print total numbers of Vowel in string
                System.out.println("Total vowel in the String - "+getVowelCount(inputString,inputString.length()));
               
                //Closing scanner
                sc.close();
        }

        /**
         * This method will get count of total number of vowel from 0 to n
         * @param str
         * @param len
         * @return
         */
        public static int getVowelCount(String str, int len) {
                if (len == 1) {
                        return isVowel(str.charAt(len - 1));
                }

                //recursive call to countVowel if len is not 1
                return getVowelCount(str, len-1) + isVowel(str.charAt(len - 1));
        }

        /**
         * Function to check the character is vowel if yes then return 1 otherwise 0
         * @param ch
         * @return
         */
        public static int isVowel(char ch) {
                //converting ch to uppercase
                ch = Character.toUpperCase(ch);
                //checking if ch is A,E,I,O or U
                if(ch=='A' || ch=='E' || ch=='I' || ch=='O' || ch=='U')  {
                        return 1;
                } else {       
                        return 0;
                }
        }

}

/Sample Output/

View attachment 1707983
Sa next request niyo po try niyo muna mag search sa ddg.gg or google.com
Para mas madali sa mag re reply
Eto po yung isa sa mga result

You do not have permission to view the full content of this post. Log in or register now.

/JAVA CODE/

/RecursiveVowels.java/


Code:
import java.util.Scanner;

/**
 * This class is used to count number of vowels present in given String
 *
 */
public class RecursiveVowels {

        //Starting point of execution
        public static void main(String args[]) {
                //Scanner is used to take user input from console
                Scanner sc = new Scanner(System.in);
               
                //Asking user to input String to find out vowel count in it
                System.out.println("Enter String to find out number of vowels :");
                //reading user input from console
                String inputString = sc.nextLine();

                // This will print total numbers of Vowel in string
                System.out.println("Total vowel in the String - "+getVowelCount(inputString,inputString.length()));
               
                //Closing scanner
                sc.close();
        }

        /**
         * This method will get count of total number of vowel from 0 to n
         * @param str
         * @param len
         * @return
         */
        public static int getVowelCount(String str, int len) {
                if (len == 1) {
                        return isVowel(str.charAt(len - 1));
                }

                //recursive call to countVowel if len is not 1
                return getVowelCount(str, len-1) + isVowel(str.charAt(len - 1));
        }

        /**
         * Function to check the character is vowel if yes then return 1 otherwise 0
         * @param ch
         * @return
         */
        public static int isVowel(char ch) {
                //converting ch to uppercase
                ch = Character.toUpperCase(ch);
                //checking if ch is A,E,I,O or U
                if(ch=='A' || ch=='E' || ch=='I' || ch=='O' || ch=='U')  {
                        return 1;
                } else {       
                        return 0;
                }
        }

}

/Sample Output/

View attachment 1707983
Sorry, nag try po ako sa google pero wala po ako makita eh, dun po sa chegg.com naman hindi makita answer need muna mag register kso may bayad po. Anyway, salamat uli
 
Last edited:

Similar threads

Back
Top