Discover a wealth of knowledge at Westonci.ca, where experts provide answers to your most pressing questions. Experience the ease of finding accurate answers to your questions from a knowledgeable community of professionals. Discover in-depth answers to your questions from a wide network of professionals on our user-friendly Q&A platform.

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!


Sagot :

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.

Writting the code in JAVA:

public class OddEvenSum {  // Save as "OddEvenSum.java"

  public static void main(String[] args) {

     // Declare variables

     final int LOWERBOUND = 1;

     final int UPPERBOUND = 1000;  // Define the bounds

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

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

     int absDiff;        // Absolute difference between the two sums

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

     int number = LOWERBOUND;   // loop init

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

           // number = LOWERBOUND, LOWERBOUND+1, LOWERBOUND+1, ..., UPPERBOUND

        // A if-then-else decision

        if (number % 2 == 0) {  // Even number

           sumEven += number;   // Same as sumEven = sumEven + number

        } else {                // Odd number

           sumOdd += number;    // Same as sumOdd = sumOdd + number

        }

        ++number;  // loop update for next number

     }

     // Another if-then-else Decision

     if (sumOdd > sumEven) {

        absDiff = sumOdd - sumEven;

     } else {

        absDiff = sumEven - sumOdd;

     }

     // OR using one liner conditional expression

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

     // Print the results

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

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

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

  }

}

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

#SPJ1

View image lhmarianateixeira