In Java only please:
4.15 LAB: Mad Lib - loops
Mad Libs are activities that have a person provide various words, which are then used to complete a short story in unexpected (and hopefully funny) ways.

Write a program that takes a string and an integer as input, and outputs a sentence using the input values as shown in the example below. The program repeats until the input string is quit and disregards the integer input that follows.

Ex: If the input is:

apples 5
shoes 2
quit 0
the output is:

Eating 5 apples a day keeps you happy and healthy.
Eating 2 shoes a day keeps you happy and healthy

Answers

Answer 1

Answer:

Explanation:

import java.util.Scanner;

public class MadLibs {

   public static void main(String[] args) {

       Scanner input = new Scanner(System.in);

       String word;

       int number;

       do {

           System.out.print("Enter a word: ");

           word = input.next();

           if (word.equals("quit")) {

               break;

           }

           System.out.print("Enter a number: ");

           number = input.nextInt();

           System.out.println("Eating " + number + " " + word + " a day keeps you happy and healthy.");

       } while (true);

       System.out.println("Goodbye!");

   }

}

In this program, we use a do-while loop to repeatedly ask the user for a word and a number. The loop continues until the user enters the word "quit". Inside the loop, we read the input values using Scanner and then output the sentence using the input values.

Make sure to save the program with the filename "MadLibs.java" and compile and run it using a Java compiler or IDE.


Related Questions

Other Questions
Which verbal connection follows a main point and serves to remind the audience of what the speaker has expressed? other than healthcare access, what are some of the most important health care issues confronting underserved communities? how would you address them? mathematical approach to understand the kinetics of -synuclein aggregation: relevance to parkinson's disease under current tax laws, a person may give any other person up to $15,000 per year in cash or other assets, and neither the giver nor the recipient of the gift has any tax liability for it. quizlet there are many examples of energy transfer within your daily routine, such as the transfer of chemical energy stored in the food that you eat to chemical energy that your cells can use (atp), fuel chemical energy in gasoline to kinetic energy to make your vehicle move, or converting electrical potential energy to energy that can light up the screen of an electronic device. Latoya was told by her manager that she could now authorize product returns without consulting him first. what is this an example of? Compared to individuals with prefrontal cortex damage, individuals with bilateral damage to the amygdala will? A bag of candy contains 3 lollipops, 8 peanut butter cups, and 4 chocolate bars. A piece of candy is randomly drawn from the bag. Find each probability.P (chocolate bar or lollipop) Several potential strategies for a project. what is the first step you would take to eliminate possible strategies? What is the angular velocity of mars as it orbits the sun? A producer has an ______ advantage in the production of a good or a sercie if his or her relative opportunity cost of production is lower than the opportunity cost of other producers What are the implications of japan's economic stagnation for the benefits, costs, and risks of doing business in this nation? Write an openflow flow entry that drops all the packets with destination address 128. 11. 11. 1 Define a function setheight, with int parameters feetval and inchesval, that returns a struct of type widthftin. the function should assign widthftin' you've found signs of unauthorized access to a web server, and on further review, the attacker exploited a software vulnerability you didn't know about. on contacting the vendor of the server software, you learn that it's a recently discovered vulnerability, but a hotfix is available pending the next software update. what kind of vulnerability did they exploit? choose the best response. with other firms that have an interest in a possible innovation share the costs and risks associated with the effort. quizlet What does the behavior of the vanes tell you about the relative amounts of charge that was separated before the last step (when the discs touched again)? Cultural capital is a concept that _______________ is mostly identified with in sociology. group of answer choices karl marx max weber mile durkheim w. e. b. dubois pierre bourdieu There are several properties of water that make Earth a suitable environment for life, including the fact that as water gets colder, density increases. This increase in density causes water to sink, creating ocean currents. In what area would this happen the most When 1-year-old children are assessed in terms of their attachment to both their mothers and fathers and are then presented with a friendly clown:____.