Advertisements
Advertisements
प्रश्न
Define a class to accept a String and Print if it is a Super string or not. A String is Super if the number of uppercase letters are equal to the number of lower case letters.
[Use Character & String methods only]
Example: “COmmITmeNt”
Number of Uppercase letters – 5
Number of Lowercase letters – 5
String is a Super Stringकोड लेखन
Advertisements
उत्तर
import java.util.*;
public class Superstring
{
public static void main(String[] args)
{
int a=0,b=0;
String sen="";
Scanner sc=new Scanner(System.in);
System.out.println("Enter the string to be
checked:");
sen=sc.nextLine();
for(int i=0;i<sen.length();i++)
if (sen.charAt(i)>='a' && sen.charAt(i)<='z')
a++;
for(int i=0;i<sen.length();i++)
if (sen.charAt(i)>='A' && sen.charAt(i)<='Z')
b++;
if (a=b)
System.out.println("String entered is a
Superstring");
else
System.out.println("String entered is a not a
Superstring");
}
}
shaalaa.com
या प्रश्नात किंवा उत्तरात काही त्रुटी आहे का?
