Counting words and occurrence coderinme

Counting words and occurrence coderinme

Write a program in Java that reads in text and prints as output the following: The number of words in the text The number of sentences in the text The number of times the letter “e” occurs in the text The number of times the letter “z” occurs in the text

import java.util.*;
public class Q29 
public static void main(String[] args) throws IOException 
BufferedReader amu = new BufferedReader(new InputStreamReader(;
System.out.println(" please enter text ");
String text=amu.readLine();
StringTokenizer st=new StringTokenizer(text);
int countE=0;
int countZ=0;
int countWords=0;
int l=text.length();
for( int i=0;i<l;i++) 
char ch=text.charAt(i);
else if(ch=='z')
System.out.println("total no of words = " +countWords);
System.out.println("total no of e = " +countE);
System.out.println("total no of z = " +countZ);

For more programs on Java, visit our Java Archives

Counting words and occurrence

All rights reserved. No part of this Post may be copied, distributed, or transmitted in any form or by any means, without the prior written permission of the website admin, except in the case of brief quotations embodied in critical reviews and certain other noncommercial uses permitted by copyright law. For permission requests, write to the owner, addressed “Attention: Permissions Coordinator,” to the admin @coderinme

Leave a reply:

Your email address will not be published.