Each Word in Separate Line StringTokenizer coderinme

Each Word in Separate Line StringTokenizer coderinme

Let us now Write a program that will read a line of text from keyboard entered by the user and then using StringTokenizer class, it will print each word of this entered text in a separate line (one word per line). Also, in the end, at the last, it will print the total number of words in the entered text by the user.

import java.io.*;
import java.util.*;
public class Q27 
public static void main(String[] args) throws IOException 
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
System.out.println("please enter any line ");
String line =in.readLine();
StringTokenizer st=new StringTokenizer(line);
int countWords=0;
while(st.hasMoreTokens()) {
String token=st.nextToken();
System.out.println("the line you have entered is: " +line);
System.out.println("total no of words are: " +countWords);

For more programs on Java, visit our Java Archives

Each Word in Separate Line StringTokenizer

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.