Question
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
-
PART A: Write a program WhileLoops that uses while loops to perform the following steps:
-
Prompt the user to input two positive integers: firstNum and secondNum (firstNum must be smaller
than secondNum).
-
Output all the even numbers between firstNum and secondNum inclusive.
-
Output the sum of all the even numbers between firstNum and secondNum inclusive.
-
Output all the odd numbers between firstNum and secondNum inclusive.
-
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
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started