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
Write a program that computes and displays a 15 percent tip when the
Anuta_ua [19.1K]
Your question wasn't very clear, but I think I understand what you want. Additionally, you should really state what language you're working with. Here it is in C#, and shouldn't be too much of a hassle to translate in to other languages.


Console.Write("Enter payment: ");

float payment;

if (float.TryParse(Console.ReadLine(), out payment))
    Console.WriteLine((Math.Floor(payment * 100) / 100) * 0.15, + " at 15% tip.");
else
    Console.WriteLine("Invalid input.");
5 0
3 years ago
Which are advantages of using a server operating system?
iogann1982 [59]

Answer:

Extra security features and networking services built right in

Explanation:

The major advantage of using a server operating system is that it has decent security features and networking services built right in it from the default settings

8 0
2 years ago
Which of these is NOT a sign that someone might be drunk
earnstyle [38]

Answer:

what are the signs someone would or would not be drunk

7 0
3 years ago
Read 2 more answers
Q4. Write down the JavaScript statements to perform the following tasks.
goldenfox [79]

Answer:

Explanation:

In Javascript, you can accept an input value by using the prompt() function and saving the input into a variable. In the following lines of code, I have declared the three variables at the beginning and then prompted the user to enter a value for each and saved the values in the correct variables. In Javascript length is a keyword so I used len instead.

let base, height, len;

base = prompt("Enter Base value: ");

height = prompt("Enter Height value: ");

len = prompt("Enter Length value: ");

5 0
2 years ago
Photographs that are too dark or too light can be difficult to fix with photo-editing software.
Nana76 [90]
The answer is true :)
6 0
2 years ago
Read 2 more answers
Other questions:
  • What is the correct order of network types when categorized by their size or the physical area they cover, from largest to small
    10·1 answer
  • Which statement describes the word "iterative"?
    9·1 answer
  • Power brakes:
    12·2 answers
  • What is DAP? How LDAP is different from DAP?
    10·1 answer
  • ________ results when leisure time and available tools allow us to engage in creative acts.
    14·1 answer
  • Users report that the network access is slow. After questioning the employees, the network administrator learned that one employ
    7·1 answer
  • Which of the following Internet protocols is MOST important in reassembling packets and requesting missing packets to form compl
    11·1 answer
  • If a student passes off an author’s work as his or her own, the student has
    6·1 answer
  • . Imagine that you were programming without an IDE. What problems might you encounter?​
    12·1 answer
  • What type of malware is best known for carrying other malware as a payload?
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!