Joined: Tue Mar 27, 2007 10:55 pm Posts: 2279 Location: Earth Has thanked: 39 time Have thanks: 61 time
Breaking the String into Words
Code:
import java.io.*; import java.util.*;
public class BreakStringToWord{ String str; int count = 0; public static void main(String[] args) { BreakStringToWord c = new BreakStringToWord(); } public BreakStringToWord(){ try{ InputStreamReader ir = new InputStreamReader(System.in); BufferedReader br = new BufferedReader(ir); System.out.print("Enter String: "); str = br.readLine(); System.out.println("Enter String is : "+ str); System.out.println("Breaking this string is : "); StringTokenizer token = new StringTokenizer(str); while (token.hasMoreTokens()){ count++; str = token.nextToken(); System.out.println(str); } System.out.println("Number of Words : "+ count); } catch(IOException e){} } }
_________________ Currenlty programming with : java , html , php , and javascript . (OCJP-6 certified )
Wednesday
Code subject: Re: Breaking the String into Words
Posted: Sat Jan 14, 2012 10:59 am
What a joy to find such clear tihinnkg. Thanks for posting!