program untuk mencetak setiap kata 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="";
      }
    }
  }
}
Nayan Kaushik