How to Make Java Read Something True for Both Upercase and Lowercase

Program to count uppercase and lowercase letter of given cord in Coffee

Plan to count capital and lowercase letter of the given string in Coffee

Contents

  • 1 Program to count uppercase and lowercase letter of the given string in Coffee
    • ane.1 Code to count capital letter or lowercase alphabetic character of the given string
      • 1.ane.1 Java code to count uppercase or lowercase letter using for loop
      • 1.1.2 Java code to count uppercase or lowercase letter using while loop
      • 1.1.three Coffee code to count upper-case letter or lowercase letter using do-while loop
    • 1.two Related posts:

In this article, we will discuss the concept of the Programme to count uppercase and lowercase letter of the given string in Java

In this post, we are going to learn how to count upper and lower case messages in a given cord in Java programming language

coutlowerupper - Program to count uppercase and lowercase letter of given string in Java
Count upper case lower case

Lawmaking to count capital or lowercase letter of the given cord

Java code to count uppercase or lowercase alphabetic character using for loop

The program allows to enter a String and it counts and displays whether the number of upper example and lower instance messages of the given string using for loop in Java language

Program 1

import java.util.Scanner; public class CountUpperLower{ public static void master(String args[]){ //variable announcement     String str; int upper=0,lower=0;//vriable declaration and initialization  Scanner scan=new Scanner(System.in);      //create a scanner object for input      Organisation.out.println("Enter the String  "); str=scan.nextLine();  for(int i=0; i<str.length(); i++){ char ch=str.charAt(i); if(ch>='A' && ch<='Z'){     upper++; } else if(ch>='a' && ch<='z'){     lower++; }  } Organisation.out.println("lowercase letters: "+lower); Arrangement.out.println("upper-case letter letters: "+upper); } }

When the above code is executed, it produces the post-obit result

Enter the String CodeForCoding lowercase letters: 10 uppercase letters: 3

Approach

  1. Declare a variable as String str;
  2. Declare and initialize two integer counter-variable as int upper=0 and lower=0;
  3. The user asked to enter a cord to count upper case and lower case messages
  4. A for-loop is used to count the total number of upper instance and lower case of the given string
  5. It is initialized every bit i=0, and checks condition whether i<str.length(); and executes the loop until the given status becomes true
  6. Use an if argument to test upper case , if the examination expression is true,  upper becomes upper + 1    (upper=upper+1)
  7. When the if-statements is false, The control moves to else if and checks the test expression of else-if
  8. If the test expression of else-if is true,  lower becomes lower + 1(lower =lower +one)
  9. If the test expression of else if is false, control terminates from the loop
  10. Finally, the program displays the number of upper case and lowercase letters of the given cord.

Coffee lawmaking to count uppercase or lowercase letter using while loop

The programme allows to enter a String and it counts and displays whether the number of upper case and lower case letters of the given string using while loop in Java linguistic communication

Program 2

import java.util.Scanner; public form CountUpperLower1{ public static void main(String args[]){ //variable proclamation     String str; int upper=0,lower=0;//vriable declaration and initialization  Scanner scan=new Scanner(Organization.in);      //create a scanner object for input      Organization.out.println("Enter the Cord  "); str=scan.nextLine();  int i=0; while( i<str.length()){ char ch=str.charAt(i); if(ch>='A' && ch<='Z'){     upper++; } else if(ch>='a' && ch<='z'){     lower++; }  i++; } System.out.println("lowercase letters: "+lower); Organization.out.println("uppercase letters: "+upper); } }

When the in a higher place code is executed, it produces the post-obit result

Enter the String Java Programming OOP lowercase letters: 13 majuscule letters: 5

Approach

  1. Declare a variable as String str;
  2. Declare and initialize two integer counter-variable equally int upper=0 and lower=0;
  3. The user asked to enter a string to count upper instance and lower case letters
  4. A while-loop is used to count total upper case and lower case of the given string
  5. It is initialized as i=0, and checks condition whether i<str.length(); and executes the loop until the given condition becomes true
  6. Use an if statement to examination upper case , if the test  expression is true,  upper becomes upper + 1    (upper=upper+1)
  7. When the if-statements is false, The command moves to else if and checks the test expression of else-if
  8. If the test expression of else-if is true,  lower becomes lower + 1(lower =lower +1)
  9. If the test expression of else if is false, control terminates from the loop
  10. Finally, the program displays the number of upper example and lowercase messages of the given cord.

Java code to count uppercase or lowercase letter of the alphabet using do-while loop

The program allows to enter a String and information technology counts and displays whether the number of upper case and lower case letters of the given string using exercise-while loop in Java language

Program 3

import java.util.Scanner; public class CountUpperLower2{ public static void main(String args[]){ //variable declaration     Cord str; int upper=0,lower=0;//vriable declaration and initialization  Scanner scan=new Scanner(System.in);      //create a scanner object for input      System.out.println("Enter a Cord  "); str=scan.nextLine();  int i=0; practise{ char ch=str.charAt(i); if(ch>='A' && ch<='Z'){     upper++; } else if(ch>='a' && ch<='z'){     lower++; }  i++; }while( i<str.length()); Organization.out.println("lowercase letters: "+lower); System.out.println("uppercase letters: "+upper); } }

When the to a higher place lawmaking is executed, it produces the following issue

Enter the String Java And CPP lowercase messages: v uppercase letters: 5

Approach

  1. Declare a variable as Cord str;
  2. Declare and initialize two integer counter-variable as int upper=0 and lower=0;
  3. The user asked to enter a string to count upper case and lower instance letters
  4. A do-while-loop is used to count full upper case and lower instance of the given cord
  5. It is initialized as i=0, and checks condition whether i<str.length(); and executes the loop until the given condition becomes true
  6. Employ an if statement to exam upper case , if the test  expression is true,  upper becomes upper + 1    (upper=upper+1)
  7. When the if-statements is false, The command moves to else if and checks the exam expression of else-if
  8. If the test expression of else-if is true,  lower becomes lower + 1(lower =lower +1)
  9. If the test expression of else if is false, command terminates from the loop
  10. Finally, the program displays the number of upper example and lowercase letters of the given string.

Suggested for you lot

for loop in Java linguistic communication

while loop in Java language

do-while loop in Coffee language

The operator in Java linguistic communication

Data blazon and variable in Coffee language

Like post

Java Program for count upper or lowercase letter of the alphabet of the given string

C Programme for count upper or lowercase letter of the given cord

Program for count upper or lowercase letter of the alphabet of the given string

Python Program for count upper or lowercase letter of the alphabet of the given string

thompsonkinters.blogspot.com

Source: https://code4coding.com/program-to-count-uppercase-and-lowercase-letter-of-given-string-in-java/

Related Posts

0 Response to "How to Make Java Read Something True for Both Upercase and Lowercase"

Enregistrer un commentaire

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel