仅供参考
package com.kidd.test.zhidao;
import java.util.Scanner;
/**
* Hello world!
*
*/
public class Execute {
public static void main(String[] args) {
int[] a = new int[5];
Scanner scanner = new Scanner(System.in);
System.out.println("请输入第一个正整数:");
a[0] = Integer.parseInt(scanner.nextLine());
System.out.println("请输入第二个正整数:");
a[1] = Integer.parseInt(scanner.nextLine());
System.out.println("请输入第三个正整数:");
a[2] = Integer.parseInt(scanner.nextLine());
System.out.println("请输入第四个正整数:");
a[3] = Integer.parseInt(scanner.nextLine());
System.out.println("请输入第五个正整数:");
a[4] = Integer.parseInt(scanner.nextLine());
System.out.println("最大数是:" + getMax(a));
System.out.println("最小数是" + getMin(a));
System.out.println("平均数是:" + getAverage(a));
}
private static int getAverage(int[] a) {
int total = 0;
for (int i : a) {
total += i;
}
return total;
}
private static int getMin(int[] a) {
int min = a[0];
for (int i = 1; i < a.length; i++) {
if (a[i] < a[i - 1]) {
min = a[i];
}
}
return min;
}
private static int getMax(int[] a) {
int max = a[0];
for (int i = 1; i < a.length; i++) {
if (a[i] > a[i - 1]) {
max = a[i];
}
}
return max;
}
}
import java.util.Scanner;
class gt {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner input=new Scanner(System.in);
int[] a=new int[5];
int max=0,min=0;
System.out.print("输入五个整数:");
for(int i = 0 ;i<5;i++)
{
a[i]=input.nextInt();
}
min = max = a[4];
for(int i=0;i<4;i++)
{
if(a[i] > max)
max=a[i];
}
System.out.println("最大的整数位:"+max);
for(int j=0;j<5;j++)
{
if(min > a[j])
min=a[j];
}
System.out.println("最小的整数位:"+min);
for(int k=0;k<5;k++)
{
sum +=a[k]
average=a[k]/5
}
System.out.println("平均值:"+average);
}
}