Search
 
SCRIPT & CODE EXAMPLE
 

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="";
      }
    }
  }
}
Comment

PREVIOUS NEXT
Code Example
Java :: how to refresh activity without intent in android 
Java :: java connect mariadb 
Java :: print colored text java 
Java :: RealmConfiguration.Builder.allowWritesOnUiThread(true) 
Java :: isprime java 
Java :: american heavy tanks of ww2 
Java :: check if string is null or empty java 
Java :: android studio float to int 
Java :: use view binding in fragment 
Java :: java loop backwards through array 
Java :: hide actionbar android 
Java :: how to change orientation of screen in android in fragmetn programmatically 
Java :: how to add transition between activities android studio 
Java :: java swing timer sleep 
Java :: Multiply two Strings Leetcode 
Java :: javafx textarea font size 
Java :: How to convert timestamp to time in java 
Java :: find object with same attribute java stream 
Java :: java.lang.ExceptionInInitializerError: null 
Java :: ++i vs i++ java 
Java :: localdate add months in java 
Java :: spigot respawn player location 
Java :: loop through a 2d array java 
Java :: how to calculate the amount of months between two dates java 
Java :: java version 
Java :: display an image java 
Java :: array to arraylist java 
Java :: java long to int 
Java :: selenide wait 
Java :: java random 
ADD CONTENT
Topic
Content
Source link
Name
2+9 =