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
MAVERICK [17]
2 years ago
6

JAVA -Develop a program that prompts the user to enter a series of 10 integers and then determines and displays the largest and

smallest values entered. The solution must use at least these following variables:
counter -a counter to count how many integers were entered
number -the integer most recently input by the user
smallest -the smallest number entered so far
largest -the largest number entered so far

Write three separate programs in JAVA , the first using a while construct, the second using a for construct, and the third using a do while construct. Thank you so much!
Computers and Technology
1 answer:
MariettaO [177]2 years ago
8 0

Using the knowledge in computational language in JAVA it is possible to write a code that enter a series of 10 integers and then determines and displays the largest and smallest values entered.

<h3>Writting the code in JAVA:</h3>

<em>public class OddEvenSum {  </em><em>// Save as</em><em> "OddEvenSum.java"</em>

<em>   public static void main(String[] args) {</em>

<em>   </em><em>   // Declare variables</em>

<em>      final int LOWERBOUND = 1;</em>

<em>      final int UPPERBOUND = 1000;  // Define the bounds</em>

<em>      int sumOdd  = 0;    // For accumulating odd numbers, init to 0</em>

<em>      int sumEven = 0;    // For accumulating even numbers, init to 0</em>

<em>      int absDiff;        // Absolute difference between the two sums</em>

<em>      // </em><em>Use a while loop</em><em> to accumulate the sums from LOWERBOUND to UPPERBOUND</em>

<em>      int number = LOWERBOUND;   // loop init</em>

<em>      while (number <= UPPERBOUND) {  // loop test</em>

<em>            // number = LOWERBOUND, LOWERBOUND+1, LOWERBOUND+1, ..., UPPERBOUND</em>

<em>         // A if-then-else decision</em>

<em>         if (number % 2 == 0) {  // Even number</em>

<em>            sumEven += number;   // Same as sumEven = sumEven + number</em>

<em>         } else {                // Odd number</em>

<em>            sumOdd += number;    // Same as sumOdd = sumOdd + number</em>

<em>         }</em>

<em>         ++number;  // loop update for next number</em>

<em>      }</em>

<em>      // </em><em>Another if-then-else</em><em> Decision</em>

<em>      if (sumOdd > sumEven) {</em>

<em>         absDiff = sumOdd - sumEven;</em>

<em>      } else {</em>

<em>         absDiff = sumEven - sumOdd;</em>

<em>      }</em>

<em>      // OR </em><em>using one liner </em><em>conditional expression</em>

<em>      //absDiff = (sumOdd > sumEven) ? sumOdd - sumEven : sumEven - sumOdd;</em>

<em> </em>

<em>      // </em><em>Print the results</em>

<em>      System.out.println("The sum of odd numbers from " + LOWERBOUND + " to " + UPPERBOUND + " is: " + sumOdd);</em>

<em>      System.out.println("The sum of even numbers from " + LOWERBOUND + " to " + UPPERBOUND + " is: " + sumEven);</em>

<em>      System.out.println("The absolute difference between the two sums is: " + absDiff);</em>

<em>   }</em>

<em>}</em>

See more about JAVA at brainly.com/question/12975450

#SPJ1

You might be interested in
A customer has a system with a Gigabyte B450 Aorus Pro motherboard. He wants to upgrade the processor from the AMD Athlon X4 950
AleksandrR [38]
This upgrade will make a big improvement from his AMD Athalon X4 950 to the AMD Ryzen 7 2700X this is because the system will have more gigabytes and a better processor
3 0
3 years ago
Read 2 more answers
Which of the following statements are true regarding Steve Jobs and Steve Wozniak? Select 3 options.
Furkat [3]

Answer:

1. Both Steve Jobs and Steve Wozniak raised $1000 by selling personal items, so that they could start Apple.

2. Steve Wozniak worked for Hewlett Packard designing calculators before starting Apple.

4. Steve Jobs never learned to code and primarily focused on design.

Explanation:

I just took the test.

8 0
3 years ago
Read 2 more answers
A formula =A1+B2 is in cell D8. If you copy that formula to cell D9, what is the new formula in cell D9? A. '=A1+B2 B. '=A2+B3 C
Georgia [21]
It has to be B. Im sure of it.
6 0
3 years ago
Read 2 more answers
a key part of staying safe is employing good habits. drag the step number to the proper sequence triple a
solong [7]

Answer:

where are the step number. I can't find any

6 0
3 years ago
A user saves a password on a website the user logs into from a desktop. Under which circumstances will the password be saved on
Alja [10]

Answer:

Same browser

Explanation:

A user saves a password on a website the user logs into from a desktop. As long as the the browser used is the same and the user has saved the password on the browser, it does not matter which device the user uses, the password would be saved on the website.

Therefore same browser is important for a website to save the password logged in from any other device.

I hope the answer was helpful.

Thanks for asking.

6 0
3 years ago
Other questions:
  • Disk scheduling algorithms in operating systems consider only seek distances, because Select one: a. modern disks do not disclos
    13·1 answer
  • Thomas Hill claims that a fruitful way to think about the badness of destroying the environment is
    15·1 answer
  • Which app is not a free app that your Microsoft account gives you access to
    6·1 answer
  • 1. W jaki sposób można wyrównać tekst po wstawieniu tabulatora?
    6·1 answer
  • A ____ network (or workgroup) consists of multiple windows computers that share information, but no computer on the network serv
    15·1 answer
  • A small, electronic chip that a manufacturer develops for use in another product (such as a digital camera or microwave oven) is
    11·2 answers
  • Java can be used to create which of the following technologies?This task contains the radio buttons and checkboxes for options.
    5·1 answer
  • You are system administrator with hundreds of host workstations to manage and maintain. You need to enable hosts on your network
    14·1 answer
  • How do I sort a code in alphabetical order that uses this FileReader inFile = new FileReader("MyStudents.txt"); in a binary sear
    5·1 answer
  • 1. Write the full forms of the following.
    5·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!