Ask Question
17 November, 13:33

Term 2 lesson 2 coding activity edhesive

+5
Answers (1)
  1. 17 November, 16:49
    0
    We need to write a program, that allows the input of words, and it stops when we enter the word "STOP". And it should not save the word STOP, and print the rest of the previous words in the form of a sentence.

    Explanation:

    import java. io.*;

    import java. util. Scanner;

    import java. util. ArrayList;

    import java. lang. Math;

    class Main

    {

    public static void main (String args[])

    {

    Scanner s1 = new Scanner (System. in);

    ArrayList sentence1 = new ArrayList ();

    System. out. println ("Enter the sentence, and input word STOP to stop entering:");

    while (0==0)

    {

    String s2 = s1. nextLine ();

    if (s2. equals ("STOP"))

    {

    break;

    }

    else

    {

    sentence1. add (s2);

    }

    }

    for (String q1: sentence1)

    {

    if (q1. contains ("a"))

    {

    System. out. println (q1);

    }

    }

    }

    }

    We create an array list here, and a string type variable to store words. We allow the user to enter the words, and we stop them when they input the word STOP. And we store all other words other than STOP in the sentence1 ArrayList, and finally, print them out as a sentence.
Know the Answer?
Not Sure About the Answer?
Find an answer to your question ✅ “Term 2 lesson 2 coding activity edhesive ...” in 📘 Computers and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers