Question

Uses a while loop to print the numbers from 3 - 19. Uses a do-while loop...

    • Uses a while loop to print the numbers from 3 - 19.
    • Uses a do-while loop to print the numbers from 42 - 56.
    • Uses a for loop to print the numbers from 87 - 95.
    • Asks the user for 2 numbers. Uses a loop to print all numbers between the given numbers, inclusive.
      • Note: Consider that your user's second number can be lower! (see example below)
      • Note: Also consider that your user might give you two of the same number.
  • Your program MUST:
    • Use a while, do-while, and for loop. The fourth loop is your choice.
    • Actively use in-line comments stating what each section of code does.
    • Use try/catch, BUT only if necessary.
    • Your program must conform to the Java coding standards
    • This is an example of what your program should output:
  • I'm going to print out the numbers 3-19 using a while loop:
    3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
    
    I'm going to print out the numbers 42-56 using a do-while loop:
    42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
    
    I'm going to print out the numbers 87-95 using a for loop:
    87 88 89 90 91 92 93 94 95
    
    Now I'll print whatever numbers you'd like!
    Give me a starting number:
    2
    Give me an ending number:
    -4
    I see that your ending number is lower. Okay, I'll count down!
    2 1 0 -1 -2 -3 -4
     ----jGRASP: operation complete.

Homework Answers

Answer #1
#include<iostream>
using namespace std;

main()
{
    int i=3;
    while(i<=19)
    {
        cout<<i<<" ";
        i++;
    }
    cout<<endl;
    int j=42;
    do
    {
        cout<<j<<" ";
        j++;
    }while(j<=56);

    cout<<endl;
    for(int k=87;k<=95;k++)
        cout<<k<<" ";

    cout<<endl;
    cout<<"enter two numbers"<<endl;
    int x,y;
    cin>>x>>y;
    if(x<=y)
    {
        for(int a=x;a<=y;a++)
        cout<<a<<" ";
        cout<<endl;
    }
    else
    {
        for(int a=x;a>=y;a--)
            cout<<a<<" ";
        cout<<endl;
    }
    return 0;
}

PS:If this answer is helpful for you then please give an upvote.

Know the answer?
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
Similar Questions
8.36 Lab 8a: Count by 3 Introduction For this lab, you will use a while loop...
8.36 Lab 8a: Count by 3 Introduction For this lab, you will use a while loop to complete the task. A while loop has this basic structure: /* variable initializations */ while (/*stop condition*/){ /* statements to be performed multiple times */ /* make sure the variable that the stop condition relies on is changed inside the loop. */ } Despite the structure of the while loop being different than that of a for loop, the concept behind it is...
1) Write a java programming using a while loop where you will add numbers and when...
1) Write a java programming using a while loop where you will add numbers and when you press number 0 it will add all your numbers and display the results. Use Scanner object. Steps: 1) Declare variables integer called sum which is equal to zero   2) Declare Scanner object   3) Declare while condition where is true   4) Inside of that condition prompt the user to enter the numbers   5) Declare variable integer called number and input the number statement   6)...
Calculate and print the area and volume of a cone inside a While  loop that goes from...
Calculate and print the area and volume of a cone inside a While  loop that goes from 1 to 20 with a step of .5. (the step is 1/2 or Point 5, so you go 10, 10.5,11, 11.5) Note: Your loop variable will need to be a double data type Use two decimal places on all numbers that are double data type. This will be a table with 3 columns. Use r as the loop counter and as the radius. Let...
4.2.2 Basic while loop with user input. JAVA Write an expression that executes the loop while...
4.2.2 Basic while loop with user input. JAVA Write an expression that executes the loop while the user enters a number greater than or equal to 0. Note: These activities may test code with different test values. This activity will perform three tests, with user input of 9, 5, 2, -1, then with user input of 0, -17, then with user input of 0 1 0 -1. See "How to Use zyBooks". Also note: If the submitted code has an...
PYTHON 3 Write a program that prints the count of all prime numbers between A and...
PYTHON 3 Write a program that prints the count of all prime numbers between A and B (inclusive), where A and B are defined as follows: A = 21212 B = A + 5000 Just a recap on prime numbers: A prime number is any number, greater or equal to 2, that is divisible ONLY by 1 and itself. Here are the first 10 prime numbers: 2, 5, 7, 11, 13, 17, 19, 23, and 29. Rules: You should first...
Write a program that finds and prints all of the prime numbers between 3 and X...
Write a program that finds and prints all of the prime numbers between 3 and X (X is input from the user). A prime number is a number such that 1 and itself are the only numbers that evenly divide it (for example, 3, 5, 7, 11, 13, 17, …). One way to solve this problem is to use a doubly nested loop (a loop inside another loop). The outer loop can iterate from 3 to N while the inner...
1) Write a java programming nested while loop where you will declare two numbers one for...
1) Write a java programming nested while loop where you will declare two numbers one for outer loop and the other one for inner while loop, and display the result. (Try using scanner) Steps: 1) Declare the variable of outer loop int and assign value of your choice 2) Declare while condition which outer variable is less the number of your choice 3) Declare variable of inner loop int and assign the value of your choice 4) Declare while condition...
Using a for Loop visual c++ Summary In this lab the completed program should print the...
Using a for Loop visual c++ Summary In this lab the completed program should print the numbers 0 through 10, along with their values multiplied by 2 and by 10. You should accomplish this using a for loop instead of a counter-controlled while loop. Instructions Write a for loop that uses the loop control variable to take on the values 0 through 10. In the body of the loop, multiply the value of the loop control variable by 2 and...
Write a java program that creates an integer array with 50 random values, prompts the user...
Write a java program that creates an integer array with 50 random values, prompts the user to enter the index of an element in the array between 0 and 49, then displays the corresponding element value. If the specified index is out of bounds, display an error message (e.g. “Out of Bounds”) and ask the user to enter another index. Use a while loop that will keep prompting the user until a valid input is received. To handle invalid inputs,...
Use C++ Write a program that first reads in how many whole numbers the user wants...
Use C++ Write a program that first reads in how many whole numbers the user wants to sum, then reads in that many whole numbers, and finally outputs the sum of all the numbers greater than zero, the sum of all the numbers less than zero (which will be a negative number or zero), and the sum of all the numbers, whether positive, negative, or zero. The user enters the numbers just once each and the user can enter them...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT