5个回答
展开全部
import java.util.Arrays;
public class Array{
public static void main(String[] args)
{
int a[]=new int []{31,26,93,44,65};
Arrays.sort(a);
System.out.println("min:"+a[0]);
System.out.println("max:"+a[a.length-1]);
int count=0,average;
for(int i = 0;i<a.length;i++)
count +=a[i];
average = count/i.length;
System.out.println("count:"+count);
System.out.println("average :"+average);
}
}
这是代码量最小的解决方案。
其中的关键是Arrays.sort(a);
静态类Arrays提供静态方法sort():用来对array进行从小到大的排序。
君子性非异也,善假于物也。
public class Array{
public static void main(String[] args)
{
int a[]=new int []{31,26,93,44,65};
Arrays.sort(a);
System.out.println("min:"+a[0]);
System.out.println("max:"+a[a.length-1]);
int count=0,average;
for(int i = 0;i<a.length;i++)
count +=a[i];
average = count/i.length;
System.out.println("count:"+count);
System.out.println("average :"+average);
}
}
这是代码量最小的解决方案。
其中的关键是Arrays.sort(a);
静态类Arrays提供静态方法sort():用来对array进行从小到大的排序。
君子性非异也,善假于物也。
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2016-08-29
展开全部
public class BBBB {
public static int max(int[] a)
{
int temp = a[0];
for(int i=0;i<a.length;i++)
{
temp = java.lang.Math.max(a[i],temp);
}
return temp;
}
public static int min(int[] a)
{
int temp = a[0];
for(int i=0;i<a.length;i++)
{
temp = java.lang.Math.min(a[i],temp);
}
return temp;
}
public static float avg(int[] a)
{
int temp = 0;
for(int i=0;i<a.length;i++)
{
temp = a[i]+temp;
}
return (float)temp/a.length;
}
public static int sum(int[] a)
{
int temp = 0;
for(int i=0;i<a.length;i++)
{
temp = a[i]+temp;
}
return temp;
}
public static void main(String[] args)
{
int[] a = new int[]{1,2,3,4,5,6,7,8};
System.out.println(max(a));//最大值
System.out.println(min(a));//最小值
System.out.println(avg(a));//平均值
System.out.println(sum(a));//和
}
}
public static int max(int[] a)
{
int temp = a[0];
for(int i=0;i<a.length;i++)
{
temp = java.lang.Math.max(a[i],temp);
}
return temp;
}
public static int min(int[] a)
{
int temp = a[0];
for(int i=0;i<a.length;i++)
{
temp = java.lang.Math.min(a[i],temp);
}
return temp;
}
public static float avg(int[] a)
{
int temp = 0;
for(int i=0;i<a.length;i++)
{
temp = a[i]+temp;
}
return (float)temp/a.length;
}
public static int sum(int[] a)
{
int temp = 0;
for(int i=0;i<a.length;i++)
{
temp = a[i]+temp;
}
return temp;
}
public static void main(String[] args)
{
int[] a = new int[]{1,2,3,4,5,6,7,8};
System.out.println(max(a));//最大值
System.out.println(min(a));//最小值
System.out.println(avg(a));//平均值
System.out.println(sum(a));//和
}
}
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
public class ArrayTest {
/**
* @param args
*/
public static void main(String[] args) {
int[] array = new int[]{1, 3, 4, 8, 19};
int minValue= array[0];
int maxValue = array[0];
int aveValue = array[0];
int countValue = array[0];
for (int i = 1; i < array.length; i++) {
if (minValue > array[i]) {
minValue = array[i];
}
if (maxValue < array[i]) {
maxValue = array[i];
}
countValue = countValue + array[i];
}
aveValue = countValue/array.length + countValue%array.length;
System.out.println("minValue:" + minValue);
System.out.println("maxValue:" + maxValue);
System.out.println("aveValue:" + aveValue);
System.out.println("countValue:" + countValue);
}
}
/**
* @param args
*/
public static void main(String[] args) {
int[] array = new int[]{1, 3, 4, 8, 19};
int minValue= array[0];
int maxValue = array[0];
int aveValue = array[0];
int countValue = array[0];
for (int i = 1; i < array.length; i++) {
if (minValue > array[i]) {
minValue = array[i];
}
if (maxValue < array[i]) {
maxValue = array[i];
}
countValue = countValue + array[i];
}
aveValue = countValue/array.length + countValue%array.length;
System.out.println("minValue:" + minValue);
System.out.println("maxValue:" + maxValue);
System.out.println("aveValue:" + aveValue);
System.out.println("countValue:" + countValue);
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
直接给你答案例子:
public class Array {
public static void main(String args[]) {
int[] a={2,5,12,45,89,45,36,95,458,6534,15,39};
int max=0;
int min=10000;
int count=0;
float aver=0;
for(int i=0;i<a.length;i++) {
if(max<a[i])
max=a[i];
if(min>a[i])
min=a[i];
count=count+a[i];
}
aver=count/a.length;
System.out.println("最小值:"+min+"\n"+"最大值:"+max+"\n"+"和值:"+count+"\n"+"平均值:"+aver);
}
}
这详细吧?
public class Array {
public static void main(String args[]) {
int[] a={2,5,12,45,89,45,36,95,458,6534,15,39};
int max=0;
int min=10000;
int count=0;
float aver=0;
for(int i=0;i<a.length;i++) {
if(max<a[i])
max=a[i];
if(min>a[i])
min=a[i];
count=count+a[i];
}
aver=count/a.length;
System.out.println("最小值:"+min+"\n"+"最大值:"+max+"\n"+"和值:"+count+"\n"+"平均值:"+aver);
}
}
这详细吧?
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
用for循环,遍历整个数组,很容易得到你想要的
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询