Sample Format Computer prj
Sample Format Computer prj
import java.util.*;
class xyz
{ // class opened
public static void main(String []args)
{ // main method opened
Scanner sc=new Scanner(System.in);
System.out.println("Enter a String");
String str=sc.nextLine();
str=str+" ";
int len=str.length(); // counting the length of the string
char ch; // initializing character ‘ch’
String w=""; // initializing String ‘w’
for(int i=0;i<len;i++)
{
ch=str.charAt(i); // extracting each characters from the string
if(ch!=' ') // comparing two characters
w=w+ch; // storing the characters of a word
else
{
System.out.println(w);
w="";
}
}
} // main method closed
} // class closed
DOCUEMENTATION :-
DATA TYPE VARIABLE NAME PURPOSE
String str Storing the input given by user
int len To count the length of the string
char ch To extract each character of string
String w To store each word
OUTPUT:-