1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
aliina [53]
3 years ago
5

Write a function named twoWords that gets and returns two words from a user. The first word is of a specified length, and the se

cond word begins with a specified letter. The function twoWords takes two parameters:
i. an integer, length, that is the length of the first word and

ii. a character, firstLetter, that is the first letter of the second word. The second word may begin with either an upper or lower case instance of firstLetter. The function twoWords should return the two words in a list. Use a while True loop and a break statement in the implementation of twoWords.

The following is an example of the execution of twoWords:

print(twoWords(4, 'B')) A 4-letter word please :two

A 4-letter word please: one

A 4-letter word please : four

A word beginning with B please : apple

A word beginning with B please: pear

A word beginning with B please: banana

['four', 'banana']
Computers and Technology
1 answer:
Mandarinka [93]3 years ago
6 0

Answer:

// Method twoWords with two arguments

public static List<String> twoWords(int length, char firstLetter) {

 // Create an object of the Scanner class to allow for user inputs

 Scanner input = new Scanner(System.in);

 // Create a list to hold the two words

 List<String> words = new ArrayList<>();

 // Create a loop that asks user to enter a particular word with length equal to

 // the one specified as first argument.

 // If the user enters the correct word,

 // insert the word in the created list and break out of this loop

 while (true) {

  System.out.print("A-" + length + " letter word please: ");

  String firstword = input.next();

  if (firstword.length() == length) {

   words.add(firstword);

   break;

  }

 }

 // Create a loop that asks user to enter a particular word whose first character is

 // the one specified as second argument.

 // If the user enters the correct word,

 // insert the word in the created list and break out of this loop

 while (true) {

  System.out.print("A word beginning with " + firstLetter + " please: ");

  String secondword = input.next();

  if (secondword.charAt(0) == firstLetter) {

   words.add(secondword);

   break;

  }

 }

 // Return the list of words

 return words;

}

Explanation:

Please go through the comments in the code to get more understanding of the code. The source code file has been attached to this response. Please download it and go through it. You can also run the code on  your machine as it contains a full implementation of the method.

Hope this helps!

Download java
You might be interested in
What was Ada Lovelace's contribution to computer science?
Alika [10]

Answer:

She made the first computer.

Explanation:

Augusta Ada King, Countess of Lovelace (née Byron; 10 December 1815 – 27 November 1852) was an English mathematician and writer, chiefly known for her work on Charles Babbage 's proposed mechanical general-purpose computer, the Analytical Engine.

8 0
2 years ago
Read 2 more answers
Which of the following declares an abstract method in an abstract C++ class? (Points : 2) public: void print();
Dahasolnce [82]

Answer:

public: virtual void print()=0;

Explanation:

An abstract class contains a pure virtual function. Pure virtual class cannot be instantiated but it can be subclassed and the subclass can provide an implementation of the function.

A virtual function declaration in the class is preceded by the virtual keyword. For example, virtual void print();

A pure virtual function declaration is followed by '=0;'

public: virtual void print()=0;

4 0
4 years ago
Why is color important for all objects drawn ?​
Sati [7]
Technically, drawing in colored pencil is simply layering semitransparent colors on paper to create vivid paintings. Every color has three qualities
7 0
3 years ago
Which of the following statements is false? A.The concepts of icons, menus and windows were originally developed by Xerox PARC.
Fudgin [204]

Answer:

(b) Windows is an open source operating system (<em>This is not correct</em>)

Explanation:

Option a is <em>correct</em> because Xerox PARC(Palo Alto Research Center), which is a subsidiary of the Xerox corporation, has been greatly responsible for invention and development in modern computing devices. Some of these developments are in Ethernet and graphical user interface (making use of menus, icons e.t.c).

Option b is <em>not correct</em> because Windows Operating system is not an open source operating system. Open source OS means users can interact with the driving code of the OS and make modifications. Windows does not support this feature. Operating systems that are open source include Linux and OpenSolaris.

Option c is <em>correct</em>. An operating system has two main components - the kernel and the user interface. The core component of an operating system is the Kernel as it interacts directly with the hardware and manages system resources. The user interface on the other hand allows users to interact with the kernel of the operating system using texts and/or graphics as commands.

Option d is <em>correct</em>. Linux operating system is an open source OS. Therefore, the source code is made available to the public for examination and modification.

8 0
3 years ago
The core of ___________ is the implementation of intrusion detection systems and intrusion prevention systems at entry points to
cestrela7 [59]

Answer:

sorry I can't understand what is this is

3 0
3 years ago
Other questions:
  • Define the following term: - hue
    11·2 answers
  • Write a C program that has the following statements: int a, b; a = 10; b = a + fun(); printf("With the function call on the righ
    12·1 answer
  • Why should the data in a reservation system that is constantly being updated be stored on a magnetic disk instead of a CD or DVD
    15·1 answer
  • A ________ restricts the number of a certain type of product that can be imported into a country.
    5·1 answer
  • What is the Most popular game out today?
    6·2 answers
  • What methods would you add to make this class declarationvery useful?
    11·2 answers
  • You can resize a row in a table by dragging the ____.
    13·1 answer
  • PLEASE ANSWER AND HURRY I'LL MARK YOU BRAINLIEST!!<br><br><br>​
    9·1 answer
  • Profitability, consumer relations, and competition are involved in what kinds of concerns in the design process?
    12·1 answer
  • For a web application we associate a web server, for a mobile application we associate a mobile server. for a decentralized appl
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!