Question

3.11 LAB: Mad Lib - loops Mad Libs are activities that have a person provide various...

3.11 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 integer as input, and outputs a sentence using those items as below. The program repeats until the input string is quit 0.

Ex: If the input is:

apples 5
shoes 2
quit 0

the output is:

Eating 5 apples a day keeps the doctor away.
Eating 2 shoes a day keeps the doctor away.

Note: This is a lab from a previous chapter that now requires the use of a loop.

import java.util.Scanner;

public class LabProgram {
public static void main(String[] args) {
/* Type your code here. */
}
}

0 0
Add a comment Improve this question Transcribed image text
Answer #1
import java.util.Scanner;

public class LabProgram {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        String word;
        int count;
        while (true) {
            word = in.next();
            count = in.nextInt();
            if (word.equals("quit") && count == 0)
                break;
            System.out.println("Eating " + count + " " + word + " a day keeps the doctor away.");
        }
    }
}

Add a comment
Know the answer?
Add Answer to:
3.11 LAB: Mad Lib - loops Mad Libs are activities that have a person provide various...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • 16.25 LAB 9A: Mad Lib - Loop (program in Python 3) Overview Objective Be able to...

    16.25 LAB 9A: Mad Lib - Loop (program in Python 3) Overview Objective Be able to implement a sentinel-controlled loop. Description Remember from Lab 3C that 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. Extend your program from Lab 3C that repeats asking the user for input and displaying the short story until the user wants to quit. Ex: Enter a name:...

  • 16.25 LAB 9A: Mad Lib - Loop Overview Objective Be able to implement a sentinel-controlled loop....

    16.25 LAB 9A: Mad Lib - Loop Overview Objective Be able to implement a sentinel-controlled loop. Description Remember from Lab 3C that 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. Extend your program from Lab 3C that repeats asking the user for input and displaying the short story until the user wants to quit. Ex: Enter a name: Eric Enter a place:...

  • You will create your own silly story based on information provided by the user. For example,...

    You will create your own silly story based on information provided by the user. For example, the parts in bold were entered by the user. For ideas see: Mad Libs. My Silly Story name: Frank Zhang whole number: 345 body part: stomach noun: cup floating point number: 1.23 clothing article: hat destination: Colorado goal: degree The resulting story is: Congratulations! Today is your 345 day. You're off to Colorado! You're off and away! You have brains in your stomach, You...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT