Advertisements
Advertisements
प्रश्न
Define a class to accept a String and print the number of digits, alphabets and special characters in the string.
| Example: | S = "KAPILDEV@83" |
| Output: | Number of digits - 2 ' Number of Alphabets - 8 Number of Special characters - 1 |
Advertisements
उत्तर
import jaya.util.*;
public class CountAlpDigiSpl {
public static void main(String[] args) {
String aldisp_str;
int i, alph, digi, spl;
alph = digi = spl = 0;
char ch;·'
Scanner sc= new Scanner(System.in);
System.out.print("\nPlease Enter Alpha Numeric Special String :
");
aldisp_str = sc.nextLine();
for(i = 0; i < aldisp_str.length(); i++)
{
ch= aldisp_str.charAt(i);
if(ch >= 'a' && ch<= 'z' | | ch >= 'A' &&
ch <= 'Z' ) {
alph++;
}
else if(ch >= '0' && ch<= '9') {
digi++;
}
else {
spl++;
}
}
System.out.println("\nNumber of Alphabet
Characters = " + alph);
System.out.println("Number of Digit
characters. = " + digi);
System.out.println("Number of Special
Characters = " + spl);
}
}APPEARS IN
संबंधित प्रश्न
Write the return data type of the following function:
endsWith( )
Define a class to accept a string, convert it into lowercase and check whether the string is a palindrome or not.
A palindrome is a word that reads the same backward as forward.
Example:
madam, racecar etc.
The output of the function "COMPOSITION". substring(3, 6):
Give the output of the following String class method:
"COMMENCEMENT".lastIndexOf('M')Give the output of the following String class method:
"devote". compareTo("DEVOTE")int x = 98; char ch = (char)x; what is the value in ch?
The output of the statement "talent". compareTo("genius") is ______.
The following code to compare two strings is compiled, the following syntax error was displayed - incompatible types - int cannot be converted to boolean.
Identify the statement which has the error and write the correct statement. Give the output of the program segment.
void calculate()
{
String a="KING",b="KINGDOM";
boolean x=a.compareTo(b);
system.out.println(x);
}Consider the array given below:
char ch[]={'A','E','I','O','U'};
Write the output of the following statements:
System.out.println(ch[0]*2);;Write the output of the following String methods:
String x="Galaxy",y="Games";
(a) System.out.println(x.charAt(0)==y.charAt(0));
(b) System.out.println(x.compareTo(y));