Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVA

program to print each word of a string

import java.util.*;
public class EachWord
{
  public static void main(String[] args)
  {
    Scanner sc=new Scanner(System.in);
    System.out.println("Enter a Sentence");
    String str=sc.nextLine();
    str=" "+str;
    String word="";
    for(int i=0;i<str.length();i++)
    {
      if(str.charAt(i)!=' ')
      {
        word=word+str.charAt(i);
      }
      else
      {
        System.out.println(word);
        word="";
      }
    }
  }
}
 
PREVIOUS NEXT
Tagged: #program #print #word #string
ADD COMMENT
Topic
Name
4+6 =