1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
tekilochka [14]
3 years ago
7

Write a recursive method to return the number of uppercase letters in a String. You need to define the following two methods. Th

e second one is a recursive helper method. public static int count(String str) public static int count(String str, int high) For example, count("WolFIE") returns 4.
Computers and Technology
1 answer:
satela [25.4K]3 years ago
4 0

Answer:

<u>Recursive function with two parameters that return the number of uppercase letters in a String</u>

public static int count(String str,int h)//Defining function

{

      if(str.charAt(0)>='A' && str.charAt(0)<='Z')//Checking the characters from A to Z

{

          h++; //incrementing the counter

          if(str.length()>=2){

              return count(str.substring(1),h);//recalling function

          }

      }

      if(str.length()>=2){

              return count(str.substring(1),h); //recalling function

      }

      return h;

  }

This is the recursive function with the name count of return type integer,having parameters str of string type and h of integer type.In this we are checking the characters at a particular position from A to Z.

<u>Recursive function with one parameter that return the number of uppercase letters in a String</u>

public static int count(String str)//Defining function

{

      if(str.charAt(0)>='A' && str.charAt(0)<='Z')//Checking the characters from A to Z

{

          count++; //incrementing the counter

          if(str.length()>=2){

              return count(str.substring(1));//recalling function

          }

      }

      if(str.length()>=2){

              return count(str.substring(1)); //recalling function

      }

      return count;

  }

This is the recursive function with the name count of return type integer,having parameters str of string type .In this we are checking the characters at a particular position from A to Z.

<u>Java program that return the number of uppercase letters in a String</u>

import java.util.*;

public class Myjava{

static int count =0;//Defining globally  

 

public static int count(String str,int h)//Defining function

{

      if(str.charAt(0)>='A' && str.charAt(0)<='Z')//Checking the characters from A to Z

{

          h++;

//incrementing the counter

          if(str.length()>=2){

              return count(str.substring(1),h);//recalling function

          }

      }

      if(str.length()>=2){

              return count(str.substring(1),h);

//recalling function

      }

      return h;

 

  }

  public static void main(String[] args)//driver function

  {

      System.out.println("Enter a string");//taking input

      Scanner scan = new Scanner(System.in);

      String s = scan.nextLine();

      int h =0;

      System.out.println("Counting the Uppercase letters: "+count(s,h));

  }

}

<u>Output</u>

Enter a string  WolFIE

Counting the Uppercase letters: 4

You might be interested in
Select the correct answer.
Setler79 [48]
C because it’s the smartest thing to do and let the other people get used to each other
6 0
3 years ago
Read 2 more answers
When you sort a cell range using a to z or z to a, what is rearranged?
kvv77 [185]
Only those cells names. Most common mistake in excel. If you want to sort rows make sure you highlight everything and then use sort function on column
5 0
3 years ago
What is an index? What are the advantages and disadvantages of using indexes? How do you use SQL to create an index?
damaskus [11]

Answer:

In DBMS, an index is a physical structure that stores the values for a specific column in a table. An index can be used to extract specific information from data and access records within a table more quickly without having to scan the whole table.

An Index can be made up of one or more columns of a table and each index maintains a list of values within that field that are sorted in ascending or descending order. Indexes cannot be seen by the users, but they are just used to speed up the queries and improve the performance of a database application

4 0
2 years ago
Organizations that have no physical ("brick and mortar") presence, but only exist because of communication and computer technolo
mylen [45]

Answer: Virtual Organisations

Explanation: Virtual Organisations are Organisations that do not have any physical presence (brick and mortar). They exist in Internet platforms, social media and are known through the use telecommunications systems and facilities. This type of organisations continously conduct their businesses and liaise with their customers only through virtual Communication platforms like the computer Communication systems.

7 0
3 years ago
Rupa would like to quickly insert a table into her document without having to worry about formatting the data in the table. Whic
USPshnik [31]
Internet tap and log on application
6 0
3 years ago
Read 2 more answers
Other questions:
  • Let K(x, y) denote the statement "x knows y" and D denote the domain of all people. Express the following English sentences as a
    9·1 answer
  • What is a critique of the feature detector model of object recognition?​?
    8·1 answer
  • A(n) ______ chart is drawn on the same worksheet as the data.
    10·1 answer
  • Assume:
    14·1 answer
  • What is a statement that adds 1 to the int j when the int counter has a value less than the int n?
    12·1 answer
  • I NEED HELP PLEASE!! I just wanted to upgrade my i3 processor to an i7. I bought new hardware (motherboard, fan, etc) and now th
    5·1 answer
  • Sarah is a busy real estate agent with a growing clientele. She is looking to purchase a new computer and software so that she c
    15·1 answer
  • Write a method that accepts a string as an argument and returns a sorted string. For example, sort("acb") returns abc. Write a t
    6·1 answer
  • 4. //Program prompts users for names and quantities for a $2.00 product and displays total for each user until “XXX” is entered
    15·1 answer
  • Which agency motors the sale and registration of vehicles and vessels within the state
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!