
Tausif K.
asked 11/20/20java program to
Accept a paragraph of text consisting of sentences that are terminated by either ‘.’ (full stop), ‘!’ (exclamation mark) or a ‘?’ (question mark). Assume that there can be maximum 10 sentences in a paragraph. Write a program to arrange the sentences in increasing order of their number of words. For Example : INPUT: Please come and attend the party. Hello! How are you? OUTPUT : Hello = 1 How are you = 3 Please come and attend the party = 6
1 Expert Answer

Patrick B. answered 11/21/20
Math and computer tutor/teacher
import java.io.*;
class TausifKText
{
String [] A;
TausifKText ()
{
A = new String[10];
}
private void Sort()
{
int N=A.length;
for (int iLoop=N-1; iLoop>0; iLoop--)
{
for (int jLoop=0; jLoop<=iLoop-1; jLoop++)
{
if (
GetWordCount(A[jLoop]) > GetWordCount(A[jLoop+1])
)
{
String tempStr = A[jLoop+1];
A[jLoop+1] = new String(A[jLoop]);
A[jLoop] = new String(tempStr);
}
}
}
}
private void InputText()
{
String inputBuffer=" ";
String textLine=" ";
Console console = System.console();
System.out.print(" Input the text :>");
inputBuffer = console.readLine();
System.out.println(inputBuffer);
A = inputBuffer.split("[.!?]");
for (int iLoop=0; iLoop<A.length; iLoop++)
{
System.out.println(A[iLoop]);
}
}
private void Output()
{
for (int iLoop=0; iLoop<A.length; iLoop++)
{
System.out.println(">" +A[iLoop] + "< # of words = " + GetWordCount(A[iLoop]) );
}
}
private int GetWordCount (String inbuff)
{
String tokens[] = inbuff.split(" ");
return(tokens.length-1);
}
private void Go()
{
InputText();
Sort();
Output();
}
public static void main(String args[])
{
TausifKText x = new TausifKText();
x.Go();
}
}
Still looking for help? Get the right answer, fast.
Get a free answer to a quick problem.
Most questions answered within 4 hours.
OR
Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.
Patrick B.
source code uploaded to RESOURCES section under this link11/21/20