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
VMariaS [17]
4 years ago
8

Mad Libs are activities that have a person provide various words, which are then used to complete a short story in unexpected (a

nd 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 5shoes 2quit 0the 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. */}}

Computers and Technology
1 answer:
Marina86 [1]4 years ago
3 0

Answer:

I am writing a C++ and JAVA program.    

import java.util.Scanner; //for using input output functions

public class LabProgram { // class name

public static void main(String[] args) {//start of main function body

Scanner input = new Scanner(System.in);

// creates input instance of  Scanner type

     String str;  // declares String type variable str for a string value

     int num;  // declares integer type variable num to hold an integer value

     str = input.next(); //scans and reads input string from user

     num = input.nextInt();  //scans and reads input integer from user

//while loop continues to execute until user enters quit 0

while(str!="quit" && num!=0) {  

/* prints the following message, for example if value of num = 2 and value of str = apples then the following print statement prints Eating 2 apples a day keeps the doctor away. */

System.out.println("\nEating " + num +" " + str + " a day keeps the doctor away.");

//takes string and integer as input again and keep taking input until user //enters quit 0

str = input.next();  

num = input.nextInt(); }   } }

Explanation:

The program is well explained in the comments mentioned with each statement of the program. The program simply prompts user to enter a string and an integer. The while loop keeps executing until user enters quit 0. The program keeps taking input string and integer from user and prints the message System.out.println("\nEating " + num +" " + str + " a day keeps the doctor away.");  The loop breaks when the use enters quit 0. The screenshot of the program along with its output is attached.

You might be interested in
Assignment 8: Personal Organizer (in edhesive or python please)
serg [7]

Answer:

eventName = []

eventMonth = []

eventDay = []

eventYear = []

def addEvent():

   userEventName = input("Enter event name: ")

   userEventMonth = int(input("Enter event month (1-12): "))

   userEventDay = int(input("Enter event day(1-31): "))

   userEventYear = int(input("Enter event year (Ex:2020): "))

   userEventMonth = validateMonth(userEventMonth)

   userEventDay = validateDay(userEventMonth,userEventDay,userEventYear)

   

   eventName.append(userEventName)

   eventMonth.append(userEventMonth)

   eventDay.append(userEventDay)

   eventYear.append(userEventYear)

   

def validateMonth(month):

   if month >= 1 and month <= 12:

       return month

   else:

       return 1

def validateDay(month,day,year):

   # invalid days

   if day < 1 or day > 31 :

       return 1

   

   # if the month is february

   if month == 2:

       isleap = False

       if year%4 == 0:

           if year%100 == 0:

               if year%400 == 0:

                   isleap = True

           else:

               isleap = True

       # if the year is leap

       if isleap:

           if day < 30:                

return day

           else:

               return 1

       else:

            if day < 29:

               return day

            else:

               return 1

           

    # month with 31 days

   if month in [1,3,5,7,8,10,12]:

       return day

    # month with 30 days

   if month in [4,6,9,11] and day < 31:

       return day

   else:

       return 1

           

def printEvents():

   print("****** LIST OF EVENTS *********")

   

   months = ['January', 'February', 'March', 'April', 'May', 'June', 'July',

         'August', 'September', 'October', 'November', 'December']

   

   for index in range(len(eventName)):

       print(eventName[index])

       print("Date: "+months[eventMonth[index] -1]+ " " + str(eventDay[index]) + ", " + str(eventYear[index]))

def printEventsForMonth(month):

   months = ['January', 'February', 'March', 'April', 'May', 'June', 'July',

         'August', 'September', 'October', 'November', 'December']

   print("****** EVENTS IN " + months[month -1] + " *********")

   

   for index in range(len(eventName)):

       if eventMonth[index] == month:

           print(eventName[index])

           print("Date: "+months[eventMonth[index] -1]+ " " + str(eventDay[index]) + ", " + str(eventYear[index]))

userChoice = "yes"

while userChoice.upper() != "NO":

   addEvent()

   userChoice = input("Do you want to enter another event? NO to stop: ")

printEvents()

Explanation:

hope this saved somebody from a mental breakdown :)

3 0
3 years ago
Read 2 more answers
What is the average gradient of the slope along the straight line CD
Anvisha [2.4K]

Answer:

is there a graph to go with this?

Explanation:

7 0
3 years ago
One main advantage of CD-ROMs is that
Norma-Jean [14]
They can hold a lot of information is what you're looking for  , i can remember having this question back when i did my GCSEs <span />
6 0
3 years ago
g Q 2 Suppose I need a data structure having the following characteristics: a) must be very space efficient, and b) I have a goo
SIZIF [17.4K]

Explanation:

a.I would choose an advanced data structure like  dispersion tables.

Scatter tables, better known as hash tables, are one of the most frequently used data structures. To get an initial idea, scatter tables make it possible to have a structure that relates a key to a value, such as a dictionary. Internally, the scatter tables are an array. Each of the array positions can contain none, one or more dictionary entries.

It will normally contain a maximum of one, which allows quick access to the elements, avoiding a search in most cases. To know at which position in the array to search or insert a key, a scatter function is used. A scatter function relates each key to an integer value. Two equal keys must have the same dispersion value, also called a hash value, but two different keys can have the same dispersion value, which would cause a collision.

B. If I eliminated the characteristic b, a possible candidate keeping the previous characteristics would be: Balanced binary trees

Balanced binary trees are data structures that store key-data pairs, in an orderly way according to the keys, and allow quick access to the data, given a particular key, and to go through all the elements in order.

They are appropriate for large amounts of information and have less overhead than a scatter table, although the access time is of greater computational complexity.

Although the storage form has a tree structure internally, this is not externalized in the API, making the handling of the data transparent. They are called balanced because, each time they are modified, the branches are rebalanced in such a way that the height of the tree is as low as possible, thus shortening the average time of access to the data.

5 0
3 years ago
JavaScript uses which property to change the current content of HTML elements?
solong [7]

Answer:

innerHTML

Explanation:

3 0
4 years ago
Other questions:
  • Where can you find additional commands to include in menu options?
    12·1 answer
  • Assume that the main method of the class named Welcome does not contain any compile-time errors. What is the name of the file ge
    11·1 answer
  • Vhat is output by the code below?<br><br> PLEASE HELP!! TIME LIMIT!!
    5·1 answer
  • What are two most common types of microcomputers? a. IBM-style PCs and Macs c. Clients and Servers b. Mainframes and Minicompute
    14·1 answer
  • What is the financial aspect for a business as to what database software they will buy?
    6·1 answer
  • A user has connected a USB 3.0 device to a computer using a 3 ft (1m) USB 3.0 cable. However, instead of an expected data transf
    9·1 answer
  • At the beginning of Section 5.2, it is stated that multiprogramming and multiprocessing present the same problems, with respect
    8·1 answer
  • OTATAYAYYAYYA HAVE A NICE DAY BEAUTIFUL PEOEOEPOPEPELELELEEL
    5·2 answers
  • Which statement best describes the difference between a spreadsheet and a database?
    9·2 answers
  • Which type of software is created on user dimension​
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!