How to split Words in a string

This is a simple program in which user enter a string and program split its words on the bases of spaces. An array of string is use to store these words and display them one by one.

Source Code


package com.ancodingpoint.ww.w;
import java.util.Scanner;

public class String_Function {

    public static void main(String[] args) {
        Scanner input = new Scanner (System.in);
        String a = "";
        
       System.out.println(" Enter Your Story Here !..... ");
        a = input.nextLine();
       String [] words = a.split(" ");
       for (String word :  words)
       {
           System.out.println(word);
           
       }
       
    }
}

Output of the Program


Java String Programming

Share on Google Plus

About Asad

Asad Niazi is Software Engineer , Programmer, Web Developer and a young mentor of BloggersTown and PProgramming. Asad Love to writes about Technology, Programming, Blogging and make money online.
    Blogger Comment
    Facebook Comment

0 comments:

Post a Comment