public static void main(String[] args) {
int[] x = {45,66,11,34,56,76,23,45,76,345,77};
bubble(x);
System.out.println("min is "+x[x.length-1]);
System.out.println("max is "+x[0]);
}
//-----------------------冒泡排序
public static void bubble(int[]a){
for(int x = 1;x
if(a[x]>=a[y]){
a[x] = a[x]^a[y];
a[y] = a[x]^a[y];
a[x] = a[x]^a[y];
}
}
}
}
简单思路可以先排序后输出。得到的结果是
min is 11
max is 345
实际上可以只遍历1次也就可以得到,都不用整体排序
public static void main(String[] args) {
int[] x = {45,66,11,34,56,76,23,45,76,345,77};
int min = x[0];
int max =x[0];
for(int i =0;i
min = x[i];
}
if(max
}
}
System.out.println(min+":"+max);
}
这样输出11:345
public class zuidazuixiao
{
public static void main(String[] args)
{
int a [] = new int[]{1,6,78,32};
int max = a[0];
int min = a[0];
for (int i = 0; i < a.length; i++)
{
if(a[i] > max)
max = a[i];
if(a[i] < min)
min = a[i];
}
System.out.println("max is :" + max);
System.out.println("min is :" + min);
}
}