Java Basic Practice Sequence features __java

Source: Internet
Author: User
Problem description

Give the number of N, find the maximum value, the minimum, and the number of N. Input format

The first behavior is an integer n that represents the number of numbers.

The second row has n number, for the given number of n, the absolute value of each number is less than 10000. Output format outputs three rows, one integer per line. The first line represents the maximum value in these numbers, the second row represents the minimum value in those numbers, and the third line represents the number of these numbers. Sample Input 5
1 3-2 4 5 Example output 5
-2
11 Data size and convention

1 <= N <= 10000.

Import Java.util.Scanner;
public class Main {public
	static void Main (string[] args) {
		int temp,max = 0,min = 0,sum=0;
		Scanner input=new Scanner (system.in);
		int N=input.nextint ();
		for (int i=1;i<=n;i++) {
			temp=input.nextint ();
			Sum+=temp;
			if (i==1) {
				max=min=temp;
			}
			if (Temp>max) {
				max=temp;				
			}
			if (temp<min) {
				min=temp				
			}
		}}
		SYSTEM.OUT.PRINTLN (max);
		System.out.println (min);
		SYSTEM.OUT.PRINTLN (sum);		
	 }		


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.