[go: up one dir, main page]

0% found this document useful (0 votes)
4 views1 page

Sample Format Computer prj

The document contains a Java program that accepts a string input from the user and displays each word on a separate line. It utilizes a loop to extract characters and identifies words based on spaces. Additionally, it includes a documentation section detailing the data types, variable names, and their purposes used in the program.

Uploaded by

santwanabh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views1 page

Sample Format Computer prj

The document contains a Java program that accepts a string input from the user and displays each word on a separate line. It utilizes a loop to extract characters and identifies words based on spaces. Additionally, it includes a documentation section detailing the data types, variable names, and their purposes used in the program.

Uploaded by

santwanabh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

PROGRAM 0:- WRITE A PROGRAM TO ACCEPT A STRING AND DISPLAY ALL THE WORDS IN SEPARATE LINE

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:-

You might also like