Q Write a program to enter any sentence and calculate total number of alphabets used in it.
SOLUTION:
import java.lang.String;
import java.util.Scanner;
class q5
{
public static void main(String args[])
{
String str;
int i = 0,count = 0;
Scanner sc = new Scanner(System.in);
System.out.println("Write:");
str = sc.nextLine();
str = str.trim();
while(i < str.length())
{
if(str.charAt(i) >= 65 && str.charAt(i) <= 91)
count++;
else if(str.charAt(i) >= 97 && str.charAt(i) <= 122)
count++;
i++;
}
System.out.print("Total no. of Alphabet: ");
System.out.println(count);
}
}
Comments
Post a Comment