Ask Question
24 September, 15:29

Term 2 lesson 2 coding activity edhesive

+1
Answers (1)
  1. 24 September, 15:50
    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 & Technology if the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers