Ask Question
4 June, 21:09

Term 2 lesson 2 coding activity edhesive

+2
Answers (1)
  1. 4 June, 23:32
    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?
Get an answer to your question ✅ “Term 2 lesson 2 coding activity edhesive ...” in 📙 Computers & Technology if there is no answer or all answers are wrong, use a search bar and try to find the answer among similar questions.
Search for Other Answers