Sara's Strings in java

Sara’s Strings in java

Sara does not like strings that have both the uppercase and the lowercase characters. She thinks only those strings are good which have only lowercase characters( wherever possible) or only uppercase characters( wherever possible).

Given a string s consisting of the English alphabets. Find the minimum number of operations required to make it good.

In one operation you can choose any character of the string and change it into uppercase or lowercase. Input The input contains a single line containing the string s.

Constraint:- 1<=|s|<=100

Output Print the minimum number of operations required to make the string good.

Example

Input: aBASDF

Output: 1

Input: agdse

Output: 0

Solution in Sara’s Strings in java:–

import java.util.*;
import java.lang.*;
import java.io.*;

public class Main
{
	public static void main (String[] args) throws java.lang.Exception
	{
		//your code here
      Scanner sc = new Scanner(System.in);
      String str = sc.next();

      char ch;
      int count=0, flag=0;
      for(int i=0;i<str.length();i++)
        {
          ch=str.charAt(i);
          if(ch>='a' && ch<='z')
          {
            count++;
          }

          if(ch>='A' && ch<='Z')
          {
            flag++;
          }
        }

      if(flag>count)
      {
        System.out.print(count);
      }
      else{
        System.out.print(flag);
      }
	}
}

Add a Comment

Your email address will not be published. Required fields are marked *