You are on page 1of 1

import java.util.

*;
public class Main {
public static void main(String[] args) {
// fill your code here
Scanner scan = new Scanner(System.in);
System.out.println("Enter the string");
String str = scan.nextLine();
String str2 = str.replaceAll(" +", " ");
String str1[] = str2.split(" ",-1);
System.out.println("The words in the string are");
for(int i = 0; i < str1.length; i++)
{
System.out.println(str1[i]);
}
}
}

You might also like