Those years, learn together Java 2-4

Source: Internet
Author: User

/** receives a number of integers entered by the user, ending with a 1 flag input,

* Find out the maximum, minimum and average values


Import java.util.*;p ublic class firstprogram{public static void Main (String args[]) {int X;int max = -2147483648;int min = 2147483647;int n = 0;int sum = 0; Scanner in = new Scanner (; System.out.print ("Input integer:"); x = In.nextint (); while (x! =-1) {sum + = x;n++;if (x > Max) max = x;if (x < min) min = x; System.out.print ("Enter next integer:"); x = In.nextint ();} System.out.println ("Max:" + max); System.out.println ("min:" + min); System.out.print ("Average:"); System.out.printf ("%.2f", (double) sum/(double) n);}}

Those years, learn together Java 2-4

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.