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
Create a method remove Evens that removes all even elements from an ArrayList of
igor_vitrenko [27]

Answer:

#include <iostream>

# include <conio.h>

using namespace std;

main()

{

int size;

cout<<"enter the size of array";

cin>>size;

int a[size],b[size];

for (int i=0;i<size;i++)

{

cout<<"enter the value in array a"<<i;

cin>>a[i];

}

for (int k=0;k<=size;k++)

{

{

 if (a[k]%2==0)

 {

  for (int l=k; l<=size;l++)

  {

   

  a[l]=a[l+1];

   

   

     }

     size=size-1;

 }

   

}

}

cout<<"\nArray list without even";

for(int j=0;j<size+1;j++)

{

cout<<"\n"<<a[j];

}

getch();

}

Explanation:

There is an array taken of variable size, the program has been written to delete the even elements from the array list. In this program "size " is the integer variable that is taken to mention the total elements of the array. Then enter the values on different index of array.

After that program find the even values and then delete these values. After the operation new array will be displayed on output.

3 0
4 years ago
Enter the name of your school or work URL and generate report.What score did it receive?
natta225 [31]

Answer:

Harold Washington College. 21.1

4 0
3 years ago
What value will be stored in the variable t after each of the following statements
olga55 [171]

Answer:

A) t = true

B) t = false

C) t = false

D) t = true

Explanation:

Part A, here 12 is greater than 1 so the condition is true.That is why "t" will hold "true".Part B, here 0 is not greater than 2 so this condition fails.Therefore "t" will hold "false" in this case.Part C,3*2=6 and we are comparing 5 with 6  Therefore condition fails here.That is why "t" will hold "false".Part D, here  we are comparing 5 with 5 and both are equal.So "t" will hold "true".

7 0
3 years ago
5.18 LAB: Output numbers in reverse Write a program that reads a list of integers, and outputs those integers in reverse. The in
Rina8888 [55]

Answer:

In C++:

#include<iostream>

#include<vector>

using namespace std;

int main(){

   int len, num;

   vector<int> vect;

   cout<<"Length: ";

   cin>>len;  

   for(int i = 0; i<len;i++){

       cin>>num;

   vect.push_back(num);}

   vector<int>::iterator iter;

   for (iter = vect.end() - 1; iter >= vect.begin(); iter--){

       cout << *iter << ", ";}    

}

Explanation:

This declares the length of vector and input number as integer

   int len, num;

This declares an integer vector

   vector<int> vect;

This prompts the user for length  

cout<<"Length: ";

This gets the input for length  

   cin>>len;  

The following iteration gets input into the vector

<em>    for(int i = 0; i<len;i++){</em>

<em>        cin>>num;</em>

<em>    vect.push_back(num);}</em>

This declares an iterator for the vector

   vector<int>::iterator iter;

The following iterates from the end to the beginning and prints the vector in reverse

<em>    for (iter = vect.end() - 1; iter >= vect.begin(); iter--){</em>

<em>        cout << *iter << ", ";}</em>

<em />

<em />

6 0
3 years ago
Write a program to create an interface Shape containing the method declarations of area and perimeter. Then, create a class Rect
irakobra [83]

Answer:

Explanation:

An interface is similar to a class, to create an interface we use interface keyword, in an interface there can be abstract methods and constants only,we can not instantiate an interface.All the variables declared inside an interface are public,static and final  by default.

While using interface child class must use implements keyword

We can define an  interface by using below syntax-

<interface> <interface-name>{

}

For example lets create Shpae interface

interface Shape{

public int area(int length, int width);

public int perimeter(int length, int width);

}

Now lets create Rectangle class-

class Rectangle implements Shape{

public int area(int length, int width){

int area = 0;

area = length * width;

return area;

}

public int perimeter(int length, int width);

int perimeter = 0;

perimeter = 2*(length+width);

return perimeter ;

}

6 0
3 years ago
Other questions:
  • Do questions have to be about school work on this website or can they be questions about video games?
    11·2 answers
  • ATM machines respond to request in__________​
    13·1 answer
  • according to the National Automobile Dealers Association, a single dealership may employ people with as many as 57 different A.
    6·1 answer
  • In some programming languages, such as C#, Visual Basic, and Java, every class you create is a child of one ultimate base class,
    8·1 answer
  • The principal objectives of computer security are to prevent unauthorized users from gaining access to resources, to prevent leg
    11·1 answer
  • Students at a university are working on a project. the project involves many computing systems working together on disjointed ta
    9·2 answers
  • Pat practices on the keyboard to improve his typing speed. When he typed the sentence It was a rainy day, he missed typing the l
    6·1 answer
  • When designing code, which of the following best describes the purpose of a Post Mortem Review?
    13·1 answer
  • Why should you be chosen over someone else? *
    5·2 answers
  • Two negative reviews and no positive reviews is enough to consider the website to have a negative reputation.
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!