Question

In: Computer Science

Write a method that computes the number of lowercase letters (a-z) characters in a String: The...

Write a method that computes the number of lowercase letters (a-z) characters in a String:

The method signature is as follows:  public int count(String s)

Solutions

Expert Solution

code:
import java.io.*;
import java.util.Scanner;
public class Main
{
   public static void main(String args[])
   {
       Scanner s=new Scanner(System.in);
       System.out.println("Enter a string");
       String s1=s.next();
       int lower=count(s1);
       System.out.println(" Number of Lower case letters : " + lower);
   }
   public static int count(String s1)
   {
   int lower=0;
   for(int i = 0; i < s1.length(); i++)
       {
           char c = s1.charAt(i);
           if (c >= 'a' && c <= 'z')
               lower++;
           else
           {
           continue;
           }
          
       }
       return lower;
   }
}

thankyou


Related Solutions

A seqstring is a sequence of 18 letters(one of the 26 lowercase letters a-z). How many...
A seqstring is a sequence of 18 letters(one of the 26 lowercase letters a-z). How many seq strings are there where the number of letters between any two occurences of the same letter is at least 2?
A password is a string of ten characters, where each character is a lowercase letter, a...
A password is a string of ten characters, where each character is a lowercase letter, a digit, or one of the eight special characters !, @, #, $, %, &, (, and ). A password is called awesome, if it contains at least one digit or at least one special character. Determine the number of awesome passwords.
Given a string, write a method called removeRepthat returns another string where adjacent characters that are...
Given a string, write a method called removeRepthat returns another string where adjacent characters that are the same have been reduced to a single character. Test the program by calling the method from the main method. For example: removeRep(“yyzzza”) à “yza” removeRep(“aabbbccd”) à “abcd” removeRep(“122333”) à “123”
Write a function named "characters" that takes a string as a parameter and returns the number...
Write a function named "characters" that takes a string as a parameter and returns the number of characters in the input string
Write a Java method that takes an input string and computes the income minus the expenses....
Write a Java method that takes an input string and computes the income minus the expenses. The income components are indicated by numbers; while the expenses from your spending are numbers starting with a minus sign '-'. The input string may contain lowercase and uppercase letters, as well as other characters. Note that Character.isDigit(char) tests if a char is one of the chars '0', '1', ..., '9'. Also recall that Integer.parseInt(string) converts a string to an int. Test cases :...
Need a c++ program to generate a random string of letters between 8 and 16 characters.
Need a c++ program to generate a random string of letters between 8 and 16 characters.
The ASCII lowercase letters are separated from the uppercase letters by 32. Thus, to convert a...
The ASCII lowercase letters are separated from the uppercase letters by 32. Thus, to convert a lowercase letter to uppercase, subtract 32 from it. Use this information to write a program that reads characters from the keyboard. Have it convert all lowercase letters to uppercase, and all uppercase letters to lowercase, displaying the result. Make no changes to any other character. Have the program stop when the user enters a period. At the end, have the program display the number...
This function takes in a string as a parameter and prints the average number of characters...
This function takes in a string as a parameter and prints the average number of characters per word in each sentence in the string. Print the average character count per word for each sentence with 1 decimal precision (see test cases below). Assume a sentence always ends with a period (.) or when the string ends. Assume there is always a blank space character (" ") between each word. Do not count the blank spaces between words or the periods...
In C++, write a program that will read up to 10 letters (characters) into an array...
In C++, write a program that will read up to 10 letters (characters) into an array and write the letters back to the screen in the reverse order. The program should prompt the user to input all values and can determine whether the input has ended by a punctuation mark such as ‘.’ (make sure that you’ll include meaningful and intuitive messages to the user). For example, if the input is abcde, the output should be edcba. Include appropriate messaging...
​Write a recursive method, vowels, that returns the number of vowels in a string. Also, write a program to test your method.
Write a recursive method, vowels, that returns the number of vowels in a string. Also, write a program to test your method.(JAVA Code)
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT