Computer Science, asked by jiyak6404, 1 year ago

Write a program to input a sentence and convert it into uppercase and count and
display the total number of words starting with a letter 'A'.
Example:
Sample Input: ADVANCEMENT AND APPLICATION OF INFORMATION
TECHNOLOGY ARE EVER CHANGING.
Sample Output: Total number of words starting with letter 'A' = 4.


LuckyYadav2578: in which language?
neesj04: The website answer follower doesn't allows to post programing language !
LuckyYadav2578: it allows

Answers

Answered by Anonymous
43

/**************************************************************************************

Java  program to input a sentence and convert it into uppercase and count and display

the total no. of words starting with a letter ‘A’.

 

Sample Input: ADVANCEMENT AND APPLICATION OF INFORMATION TECHNOLOGY ARE EVER CHANGING

Sample Output: Total number of word Starting with letter ‘A’= 4

Code created by Mahnaz Hazra

**************************************************************************************/

 

import java.util.Scanner;

class CountLetterA

{

   public static void main(String[]args)

{

 Scanner kb = new Scanner(System.in);

 System.out.print("Enter a sentence: ");

 String str=kb.nextLine();

 str=str.toUpperCase();

 int count=0;  

 for(int i=0;i<str.length();i++)

 {

  if(i==0&&str . charAt(i)=='A')

   count++;

  if(i>0)

   if((str . charAt(i - 1) == ' ')&&(str . charAt(i)=='A'))

   count++;

 }

 System.out.println("Total number of words Starting with letter 'A'= "+count);

}

}

Attachments:
Answered by lol34590
4

Answer:

import java.util.*;

class Upper

{

public static void main(String args[])

{

Scanner inp=new Scanner(System.in);

String s=new String();

System.out.println("Enter a line:");

s=inp.nextLine();

char c;

int hi=0;

for(int i=0;i<s.length();i++)

{

c=s.charAt(i);

if(c>=65 && c<=90)

{

hi++;

}

}

System.out.println("Total number of words start with capital letters are :"+hi);

}

}

Explanation:

Similar questions