Question

In Java Design a simple program that will prompt and get a series of integers from...

In Java Design a simple program that will prompt and get a series of integers from the user. The first

integer is special in that it indicates how many integers will follow. Once your program has

received all of the integers, compute and display the sum, the largest number entered, the

smallest number entered,and the average for all of the numbers entered.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

import java.util.Scanner;

public class SeriesIntegers {
   public static void main(String[] args) {
       Scanner sc = new Scanner(System.in);
       int min = 0, max = 0, count = 0, n;
       double sum = 0;
       boolean flag = true;
       System.out.println("Enter integer (-1 to quit): ");
       while (true) {
           n = sc.nextInt();
           if (n == -1)
               break;
           sum += n;
           count++;
           if (flag) {
               flag = false;
               min = n;
               max = n;
               continue;
           }
           if (n > max)
               max = n;
           if (n < min)
               min = n;
       }
       System.out.println("Sum of elements: " + sum);
       System.out.println("Average of elements: " + (sum / count));
       System.out.println("Largest element: " + max);
       System.out.println("Smallest element: " + min);

   }
}

Note : Please comment below if you have concerns. I am here to help you

If you like my answer please rate and help me it is very Imp for me

Add a comment
Know the answer?
Add Answer to:
In Java Design a simple program that will prompt and get a series of integers from...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT