Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

IN JAVA PART A: Write a program WhileLoops that uses while loops to perform the following steps: Prompt the user to input two positive integers:

IN JAVA

  1. PART A: Write a program WhileLoops that uses while loops to perform the following steps:

    1. Prompt the user to input two positive integers: firstNum and secondNum (firstNum must be smaller

      than secondNum).

    2. Output all the even numbers between firstNum and secondNum inclusive.

    3. Output the sum of all the even numbers between firstNum and secondNum inclusive.

    4. Output all the odd numbers between firstNum and secondNum inclusive.

    5. Output the sum of all the odd numbers between firstNum and secondNum inclusive.

Enter an integer: 

3

Enter another integer larger than the first one:

10

Even numbers: 4 6 8 10 Sum of even numbers = 28 Odd numbers: 3 5 7 9 Sum of odd numbers = 24 

PART B: Re-write the program above using for loops. Name the class ForLoops.

PART C: Write a program Digits that prompts the user to input a positive integer and then outputs the number reversed and the sum of the digits. For example, if the user enters the number 3456, then your program should output 6543 and the sum as 18.

Use a while loop.EXAMPLE OUTPUT:

Enter an integer: 

3478246

Number reversed: 6428743 Sum of digits: 34 

You may assume the user enters a number smaller than the max int (2,147,483,647).

PART D: Write a program Stars that uses two nested for loops to output the pattern of stars shown below (note that there are no spaces in between stars).

EXAMPLE OUTPUT:

Enter an integer from 3 to 10: 7

******* ****** *****

****

***

** *

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Data And Information Quality Dimensions, Principles And Techniques

Authors: Carlo Batini, Monica Scannapieco

1st Edition

3319241060, 9783319241067

More Books

Students also viewed these Databases questions