0 basic Java language Fifth week array--averaging number examples

Source: Internet
Author: User
Package Shuzu;import Java.util.scanner;public class Shuzu_pjs {public static void main (string[] args) {//user input a series of numbers and then find out which The number Scanner in = new Scanner (system.in), and the output number is greater than the average. System.out.println ("How many values do you want to enter?") Please enter: ");//Calculate the average, need to have: 1. Record each number of inputs n; number of inputs and sum; number of input values cnt;int cnt = In.nextint ();//Calculate average, define sum as floating-point double sum = 0; System.out.println ("Enter your value:");//create an array called num, and enter the values for each entry. int[] num = new int[cnt];//iterates over the array num, assigns each number entered to num[i]for (int i=0;i<cnt;i++) {Num[i] = In.nextint ();//By the way, the sum of the input values is computed Sum + num[i];} System.out.println ("The average of these numbers is:" +sum/cnt);//iterate over the array num, which will be greater than the sum of the number output for (int i=0; i<cnt; i++) {if (num[i]>sum/cnt) { System.out.println (num[i]+ "");}}}


0 basic Java language Fifth week array--averaging number examples

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: info-contact@alibabacloud.com 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.